How to plot an array of complex numbers using a For Loop and each point uses a different image/color.
조회 수: 4 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Jan
2017년 8월 27일
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
Charlie Wannall
2020년 2월 26일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
