add legend after a loop
조회 수: 12 (최근 30일)
이전 댓글 표시
im bulding a program that finds the roots' the last number change from 0 to 20. after that im plot the result' and i want to add legend for each result. im probably getting complex numbers.
clear all;
close all;
Legend=cell(19,1)
for k=0:20
p=[1 2 4 k]
r=roots(p);
figure(1)
hold on;
plot(r,'*')
hold on;
end
axis ([-3.5 0.7, -3 3])
grid on;
plot( 0, [-3:0.01:3],'k.-')
hold off;
xlabel('Re(s)')
ylabel('Im(s)')
title('system poles with diffeent k')
댓글 수: 0
답변 (1개)
KSSV
2022년 4월 8일
May be something like below:
figure(1)
hold on
for k=0:20
p=[1 2 4 k] ;
r=roots(p);
plot(r,'*','DisplayName',num2str(k))
end
axis ([-3.5 0.7, -3 3])
grid on;
plot( 0, [-3:0.01:3],'k.-','DisplayName','out of loop')
hold off;
xlabel('Re(s)')
ylabel('Im(s)')
title('system poles with diffeent k')
legend show
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!