How to plot in a for loop?
古いコメントを表示
my graph is showing up, but the plot is blank. Does anyone know why? Thank you.
TimeOut=input('Press Enter to view velocity and acceleration of the wiper process in increments of 5 degrees')
hold on
for i=[0:5:90]
L1=3; %in feet
L2=3; %in feet
r1=[-L1*sind(i),L1*cosd(i),0];
i2 = asind(-L1*sind(i)/(L2));
r2=[L2*sind(i2),L2*cosd(i2),0]; %array
r0 = r1(2)+r2(2); %r0=length of travel of mechanism
disp(sprintf('Length of travel of mechanism is %0.2f feet\n',r0(1)));
vb=cross(W, r1);
w2=[0, 0, L1*cosd(i)/(L2*cosd(i2))];
vc=[0,-W(3)*-L1*sind(i)-w2(3)*L2*sind(i2),0];
%Make sure the velocity of the mechanism is not to exceed 480mm/s
if abs(vc)>=1.5748; %480mm/s = 1.5748ft/s
disp('Velocity exceeds 480mm/s. Refine inputs.')
break
end
%Find Acceleration
anb=cross(W, cross(W, r1)); %Normal Acceleration of b
atb=cross(alpha1, r1); %Tangential Acceleration of b
ancb=cross(w2, cross(w2, r2)); %Normal Acceleration of c/b
alpha2=[0, 0, -(anb(2)+atb(2)+ancb(2))/r2(1)];%Angular Acceleration of link 2
atcb=cross(alpha2, r2);%Tangential Acceleration of b
ac=anb + atb + ancb + atcb;%Acceleration of wiper (point C)
disp(sprintf('Velocity of wiper is %0.2f ft/s\n',vc(2)));
disp(sprintf('Acceleration of wiper is %0.2f ft/s^2\n',ac(1)));
subplot(2,1,1)
plot(i,vc(2))
grid
xlabel('Angle in Degrees')
ylabel('Velocity')
subplot(2,1,2)
plot(i,ac(1))
grid
xlabel('Angle in Degrees')
ylabel('Acceleration')
end
6 件のコメント
Cam Salzberger
2017 年 10 月 23 日
Nicole - you've removed the majority of your question, including all of your code. Can you add that back so that future visitors can have context to your question?
Are you still running into issues, or is this question resolved?
Cam Salzberger
2017 年 10 月 23 日
I would suggest inspecting the data that you are plotting. If that all looks correct (a long vector with varying values), then check the plot itself. You can see how many lines are present in a plot with:
hLines = get(gca, 'Children')
You can look at the 'XData' and 'YData' of the lines to ensure that there is proper data there. Then check that the axes limits are big enough that they would show more than one point. Then check coloring - white on white doesn't show up very well.
Cam Salzberger
2017 年 10 月 23 日
Looks like your line has only a single point then. See the XData and YData fields. If you want the line to be all your data, the call to plot needs to be with vectors.
Make sure that you are building the vectors a point at a time. In other words, that you are doing:
velVals(k) = vc(2);
accelVals(k) = ac(1);
and not:
velVals = vc(2);
accelVals = ac(1);
Cam Salzberger
2017 年 10 月 24 日
You are plotting just "i" against "vc(2)" outside the loop. It will only display the last value those variables were assigned. You should be plotting "x" against "V" and "x" against "A".
Cam Salzberger
2017 年 10 月 24 日
I had assumed you were cutting out the rest of your loop code in your post not literally cutting it out. Yes, "V" and "A" will contain the same value for every element if you loop through each element and assign the same value to it. When I suggested you follow a structure similar to this:
for i = iVals
...
velVals(i) = vc(2);
...
accelVals(i) = ac(1);
...
end
I meant:
for i = iVals
...PUT CALCULATIONS FOR vc HERE...
velVals(i) = vc(2);
...PUT CALCULATIONS FOR ac HERE...
accelVals(i) = ac(1);
...DO ANYTHING ELSE YOU NEED TO DO IN THE LOOP HERE...
end
I'm not here to write your code for you fully and completely. I'm just trying to give you suggestions on how you can resolve the issues you are facing and allow you to apply them to your own code.
Hopefully this helps clear up the misunderstanding.
-Cam
Rena Berman
2017 年 10 月 30 日
(Answers Dev) Restored edit
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Graphics Performance についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!