how to add iterations to a matrix as values in a loop and then manipulate the matrix with another matrix from the user interface

5 views (last 30 days)
hello
iam making a force analysis program the prog first takes some data from the user and then gets the unknown forces through 2 matrices V=a\b where a is the coeff matrix and b is the constant matrix the problem is the user is asked to enter 1 value of theta and it works fine give the forces at this theta but when i insert theta as th2=0:1:360 give a CAT arguments dimensions are not consistent.error i want to get the forces and get the corresponding theta and then plot them ..... any help would be great thnx in advance
the code is a push button callback
axes(handles.axes1)
th2=[1:360];
alp2=handles.edit4;
l2=handles.edit1 ;
r2=handles.edit10;
w2=handles.edit3;
m2=handles.edit5 ;
u=handles.edit9 ;
l3=handles.edit2 ;
r3=handles.edit11 ;
m3=handles.edit6;
fp=handles.edit14;
e=handles.edit8;
m4=handles.edit7;
th2r=th2*(pi/180);
i3=get(handles.text56, 'string');
i3n=str2double(i3);
i2=get(handles.text55, 'string');
i2n=str2double(i2);
%%%%%%%%%%%%%Velocity and acc
th3=asin(((e)+(l2)*(sin(th2r)))/(l3));
w3=(-w2)*((l2*cos(th2r))/((l3)*cos(th3)));
alp3=(((w2)^2)*(l2)*(sin(th2r))+((w3)^2)*(l3)*(sin(th3))-(alp2)*(l2)*(cos(th2r)))/((l3)*(cos(th3)));
alp4=(-alp2)*(l2)*(sin(th2r))-(alp3)*(l3)*(sin(th3))-((w2)^2)*(l2)*(cos(th2r))-((w3)^2)*(l3)*(cos(th3));
ag3x=-(w2^2)*(l2)*(cos(th2r))-(alp2)*(l2)*(sin(th2r))-(w3^2)*(l3/2)*(cos(th3))-(alp3)*(l3/2)*(sin(th3));
ag3y=-(w2^2)*(l2)*(sin(th2r))+(alp2)*(l2)*(cos(th2r))-(w3^2)*(l3/2)*(sin(th3))+(alp3)*(l3/2)*(cos(th3));
thag3=atan(ag3y/ag3x);
ag2=sqrt(((w2^2)*(l2/2))^2+((alp2)*(l2/2))^2);
thag2=atan(((alp2)*(l2/2))/((w2^2)*(l2/2)));
ag2x=ag2*cos(thag2);
ag2y=ag2*sin(thag2);
%%%%%%%%%%%%%%%%%%Force analysis
%%%%%%here is the two matrices where the forces comes from and the torque which i want to plot with th2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%A-(8*8)
A=[1 0 -u 0 0 0 0 0;
0 1 1 0 0 0 0 0;
-1 0 0 1 0 0 0 0;
0 -1 0 0 1 0 0 0;
(-l3/2)*sin(th3) (-l3/2)*cos(th3) 0 (-l3)*sin(th3) (-l3)*cos(th3) 0 0 0;
0 0 0 -1 0 0 1 0;
0 0 0 0 -1 1 0 0;
0 0 0 (l2)*sin(th2r) (l2)*cos(th2r) 0 0 -1];
%%%%%%B(8*1)
B=[(m4*alp4+fp);%%%%
(m4*9.81);
(m3*ag3x);
(m3*ag3y);
(i3n*alp3);%%%%%%%%%%
(m2*ag2x);
(m2*ag2y+m2*9.81);
(((i2n+m2*((l2/2)^2))*alp2)+(l2/2)*cos(th2r))];
V=A\B;
T=V(8,1)
%%%%here i want T to came as a vectoe with 360 value
plot(th2,T)
%%%%%%%%%%%%%%%%%%%%%%%
this is the whole code
dont know how to get T as a vector
and plot it with th2
the values above are entered from the user expect th2 is an iteration
the error mssg is
??? Error using ==> vertcat
CAT arguments dimensions are not consistent.
Error in ==> GUIWORK>pushbutton3_Callback at 757
A=[1 0 -u 0 0 0 0 0;
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> GUIWORK at 43
gui_mainfcn(gui_State, varargin{:});
Error in ==>
@ (hObject,eventdata)GUIWORK('pushbutton3_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback

Accepted Answer

Oleg Komarov
Oleg Komarov on 3 May 2011
The expressions in A:
(-l3/2)*sin(th3)
(l2)*sin(th2r)
...
should be scalar, which means that th2r and th3 should be scalars.
  1 Comment
bassam  imam
bassam imam on 5 May 2011
i cant make them scalar because i want to plot with a-lot of values not a single point can you help me to make a loop ? to iterate a vector of torque and theta2? theta 2 from 0:360 and the opposite values for theta 2
thnx in advance

Sign in to comment.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!