Add numbers into legend with for loop

조회 수: 1 (최근 30일)
Yasin AHLATCI
Yasin AHLATCI 2020년 6월 17일
편집: madhan ravi 2020년 6월 17일
clc;
x=linspace(-180,180,200);
xr=x*(pi/180);
for (i=1:4)
subplot(2,2,i)
t=cos(i*xr);
plot(x,t)
axis([-180 180 -1 1]);
grid on;
legend('cos(i*xr);
end
----
This is my code. I wonder if i could write i inside of legend like;
i=1 i want cos(1*xr)
i=2 i want cos(2*xr) ...
How can i do that ?

답변 (1개)

madhan ravi
madhan ravi 2020년 6월 17일
편집: madhan ravi 2020년 6월 17일
legend(sprintf('cos(%d*xr)',i))

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by