![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/409000/image.jpeg)
Problems plotting and adding legend to certain point in a plot
조회 수: 4 (최근 30일)
이전 댓글 표시
Hi,
I have a simple code that plots 7 eigenvalues as follows:
A = load('XV15A_200kts_A9.txt');
Result = eig(A)
plot(Result,'+')
What I would like to do is for pairs of points (ie -2 + 0.5i and -2 - 0.5i) to have a different colour to other points and I would ideally like to label these points in the legend (so in this example i would like the two points to be marked red and in the legend say 'Dutch Roll Mode')
Any help would be appreciated
댓글 수: 0
답변 (1개)
Setsuna Yuuki.
2020년 11월 10일
to place the dots with different colors:
compleja = 0;
A = rand(100);
result = eig(A)
j = 1;
for i = 1:length(result)-1
if(result(i) == conj(result(i+1)))
compleja(j) = result(i);
j = j+1;
end
end
result = result(2:length(result));
resultReal = real(result); resultComplex = imag(result);
scatter(resultReal,resultComplex,'g +','linewidth',2); hold on;
resultReal = real(compleja); resultComplex = imag(compleja);
scatter(resultReal,resultComplex,'r +','linewidth',2)
compleja = conj(compleja);
resultReal = real(compleja); resultComplex = imag(compleja);
scatter(resultReal,resultComplex,'b +','linewidth',2)
xlabel('Real'); ylabel('Imaginario')
legend('Only Real','Red category','Blue category')
A example with 100x100 matrix:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/409000/image.jpeg)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!