How to plot an array of complex numbers using a For Loop and each point uses a different image/color.
4 views (last 30 days)
Show older comments
I have a homework assignment that reads as such:
"Plot each complex number in the two problems above (12 dierent points) in MATLAB using a unique symbol/color combination for each point. Label the real and imaginary axes and provide a legend. Store all these complex numbers in a single array and use a for loop to make your plot. This means there will only be one line that uses the plot command, located inside the for loop."
I have my code written most of the way but I do not have a way to plot each point individually using a For Loop. I can plot them all as circles using:
For index = 12
plot (z,'o')
end
but I do not have a way with this method to plot unique points. All of the help sites tell me to use the Hold On command, or list z1, z2, z3... and plot it all as one thing, but I can only use the plot command once (so Hold on won't help) and I have to use an array (so plot (z1, 'o', z2, 's'...) won't help either.
0 Comments
Answers (1)
Jan
on 27 Aug 2017
Did you try to run you code? Start with a proper for loop:
for index = 1:12
Lower "for" and the loop does not run over the scalar 12, but from 1 to 12.
Now use the index inside the loop: z(index). If this is a complex number, how can you draw it to an x and y axis?
The documentation of plot explains, how to use specific colors and symbols. Maybe you want to use a cell string as a list of symbols. See also colormap to create a list of colors.
Finally the advice was correct: hold on helps to avoid, that each plot command clears the fromerly drawn objects.
2 Comments
Charlie Wannall
on 26 Feb 2020
Hey friend,
Make sure to have "hold on". It looks like all you are seeing is the last result as it just plotted the last point with the last linespec of 4 + 2i with "s" (a square) which implies it's writing over previous plots as it goes through the for loop.
Cheers
See Also
Categories
Find more on Data Distribution Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!