How do I plot all my points in the same figure?
2 次查看(过去 30 天)
显示 更早的评论
I'm trying to plot the iterations in one figure, however, I'm getting over 80+ figures. Can anyone help me fix this? Sorry in advance if this code is disturbing.
The code is supposed to find all the iterations of V1 until the error converges to 0.001.
for i=0.0001:0.001:1
V1_iter= V1 - i;
error= (V1 - V1_iter)/V1;
plot(error,V1_iter,'r-*')
title('Graph of Iteration vs Error');
xlabel('Error');
ylabel('Iteration V1');
hold on;
if error == 0.001
end
figure
drawnow;
0 个评论
回答(2 个)
MathReallyWorks
2017-6-10
编辑:MathReallyWorks
2017-6-10
Hello sarah,
You are getting 80+ figures because you have used
figure
in your for loop.
This instruction always opens a new figure in each iteration.
Remove this line of your code, then it will work well.
If the above code is the part of main program then use "figure" just above your for loop.
Now, it works well:
for i=0.0001:0.001:1
V1_iter= V1 - i;
error= (V1 - V1_iter)/V1;
plot(error,V1_iter,'r-*')
title('Graph of Iteration vs Error');
xlabel('Error');
ylabel('Iteration V1');
hold on;
if error == 0.001
end
drawnow;
end
0 个评论
Image Analyst
2017-6-10
编辑:Image Analyst
2017-6-10
Simply get rid of the call to "figure" in your loop. If you don't have it, it will plot into the current axes, or automatically create a figure with an axes on it for you if you don't already have a figure. So you don't need figure at all unless you already have an existing figure that you don't want to draw in and want to create a second separate axes.
Also, it's recommended that you don't use i or j (imaginary variables) for a loop index. Use k or something:
for k = 0.0001 : 0.001 : 1
V1_iter = V1 - k;
error = (V1 - V1_iter) / V1;
plot(error, V1_iter, 'r-*')
title('Graph of Iteration vs Error');
xlabel('Error');
ylabel('Iteration V1');
hold on;
if error == 0.001
end
drawnow;
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!