![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/175415/image.png)
Holding Plots In A Loop
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hello,
I am trying to subplot 2 figures, i.) n-th roots of unity and ii.) one other complex number. While the complex number plot comes as fine, the root of unity plot Windows is lefts blank, additionally I get another blank window. Where have I mistaken? Here is the code:
figure
subplot(2,1,1) % add first plot in 2 x 1 grid
plot(c1, '+');
title('Plot of the Product')
subplot(2,1,2)
hold on;
while lim_plot > 0
plot(nthroot(1,lim_plot), '*');
lim_plot = lim_plot - 1;
end
hold off;
title('Roots of Unity')
So, instead of having multiple superimposed plots for root's of unity, I have just 1. I want all the roots of unity until the user input limit lim_plot to be superimposed in the second graph!
Thanks.
0 comentarios
Respuestas (1)
Nick Counts
el 4 de Nov. de 2016
Your sample code was missing some variable definitions, so there may be other issues, but here is what I see:
Assuming that you are passing your lim_plot > 0 test, your next line is calls nthroot on the vector [1] and asks for the lim_plot^th real root of [1].
help nthroot
If I change that line to:
plot(nthroot(c1,lim_plot), '*');
I get the output you are looking for (assuming that my dummy lim_plot and c1 variables are similar to yours).
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/175415/image.png)
Hopefully that helps.
Cheers
0 comentarios
Ver también
Categorías
Más información sobre Subplots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!