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0 0 0 0 0 0 0 0.9806 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.1961 0 0 1];
b=[0 k 0 k 0 k 0 k 0 k 0 0 k 0 8000 0 k -5000 0 5000 8660.254+k]';
format long
y=A;
for f1=k
plot(f1,-y(1,:),'b*',f1,-y(2,:)+y(6,:)-0.7071-y(3,:),'g^',f1,y(5,:)+0.7071*y(3,:),'k+')
hold on
end
for f2=k
plot(f2,-y(5,:)-0.7071*y(7,:),'b*')
hold on
end
end
My matlab code works fine, but the only thing that i can't do is print two seperate graphs. If i try to include a 'hold off' anywhere in the code, it only plots a single dot on one graph. If i try to include a 'figure' anywhere in the code it prints a 1000 graphs and matlab crashes.
My question is how can i effectively fix my code so that it prints a graph separately for each 'for' loop for f1 and f2.
Explanation / Answer
you can use the subplot(m,n,p) function to plot separate graphs in separate parts on the screen.
the argument m and n divides the screen into a m*n grid and p specifies the positon of graph.
Eg subplot(2,1,1) means the screen will be divided into 2 rows and 1 column and the graph will be plotted in 1st cell, that is 1st row and 1st column.
I included the command in your code:-
n=7500;
for k=1:n
A=[-1 0 -0.7071 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 -1 -0.7071 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0.7071 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 -1 0 -0.7071 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 -1 0 0 0.7071 1 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 -1 -0.7071 0 0 1 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0.7071 0 1 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 -1 0 -0.7071 0 0 0.9806 0.7071 0 0 0 0 0 0
0 0 0 0 0 0 0 -1 0 0 0.7071 0 1 0.1961 0.7071 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 -1 -0.7071 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0.7071 1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 -0.9806 0 0 0 0.9806 0.7809 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 -0.1961 0 0 1 0.1961 0.6247 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.7071 -1 0 0 0 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.7071 0 -1 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.7809 -1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.6247 0 -1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.9806 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.1961 0 0 1];
b=[0 k 0 k 0 k 0 k 0 k 0 0 k 0 8000 0 k -5000 0 5000 8660.254+k]';
format long
y=A;
for f1=k
subplot(2,1,1);%subplot
plot(f1,-y(1,:),'b*',f1,-y(2,:)+y(6,:)-0.7071-y(3,:),'g^',f1,y(5,:)+0.7071*y(3,:),'k+')
hold on
end
for f2=k
subplot(2,1,2); %subplot
plot(f2,-y(5,:)-0.7071*y(7,:),'b*')
hold on
end
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.