Holding Plots In A Loop

4 Ansichten (letzte 30 Tage)
Amritpal Kaur
Amritpal Kaur am 3 Nov. 2016
Beantwortet: Nick Counts am 4 Nov. 2016
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.

Antworten (1)

Nick Counts
Nick Counts am 4 Nov. 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).
Hopefully that helps.
Cheers

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by