MATLAB: How to set value of a loop to be the contents of an array

for loop

Hello
I wanted to solve 4 equations in 4 unknowns with one being a variable input from 0 to 360, so 1st I wrote an m file
function w=position(theta,a)
w=[(100)+ (175*(cos(theta(2))))-(200*(cos(pi*a/180)))-(150*(cos(theta(1))));
(175*(sin(theta(2))))-(200*(sin((pi*a/180))))-(150*(sin(theta(1))))];
end
Then I made a loop
i=1;
options=optimset('display','off');
for th=0:5:360
the(i)=th;
theta34(:,i)=fsolve(@position,[1 1],options,th)*180/pi;
i=i+1;
end
plot(the(1,:),theta34(1,:));
hold;
plot(the(1,:),theta34(2,:));
grid;
and I got theta34 as an array, now I want to use theta34(2,:) as the value for a for loop to solve the other 2 equations, so i wrote another m file
function w=position1(theta,a)
w =[(theta(2))+(175*(sin(pi*a/180)))+(300*(sin(theta(1))));
(175*(sin(pi*a/180)))+(300*(sin(theta(1))))];
end
and made a similar loop
i=1;
options=optimset('display','off');
for th=theta34
the(i)=th;
theta56(:,i)=fsolve(@position1,[1 1],options,th)*180/pi;
i=i+1;
end
plot(the(1,:),theta56(1,:));
hold;
plot(the(1,:),theta56(2,:));
grid;
however I can't figure out how to turn the values of the loop instead of (for ex.) 0:5:360 to theta34(2,:1)
Thanks in advance

Best Answer

Ahmed - if you want to iterate over the elements in the second row of theta34, then you should be able to do something like
for k=1:length(theta34(2,:))
th = tehta34(2,k);
% etc.
end