필터 지우기
필터 지우기

How to plot a variable increasing in a for loop

조회 수: 29 (최근 30일)
Christopher Deas
Christopher Deas 2023년 2월 8일
댓글: Steven Lord 2023년 2월 8일
for F1 = 0.1:0.01:1
f1 = (F1*fs);
f2 = ((F1-0.001)*fs);
end
plot(f1,f2,"*-") %????
This currently brings a plot in the right scale but with only one point on it. Essentially i want every iteration of f1 and f2 as F1 increases to be plotted.
  댓글 수: 1
Sarvesh Kale
Sarvesh Kale 2023년 2월 8일
do you want f1 vs F1 and f2 vs F1 on the same graph ?

댓글을 달려면 로그인하십시오.

답변 (2개)

Les Beckham
Les Beckham 2023년 2월 8일
You should read this documentation page: Array Indexing
Also, I would recommend taking the time to go through the online tutorial here: Matlab Onramp

Jan
Jan 2023년 2월 8일
편집: Jan 2023년 2월 8일
If the plot should be expanded in each iteration, move the plot command inside the loop:
axes('NextPlot', 'add'); % As hold('on')
for F1 = 0.1:0.01:1
f1 = F1 * fs;
f2 = (F1 - 0.001) * fs;
plot(f1, f2, "*")
end
A better option is to create vectors inside the loop:
F1 = 0.1:0.01:1;
for k = 1:numel(F1)
f1(k) = F1(k) * fs;
f2(k) = (F1(k) - 0.001) * fs;
end
plot(f1, f2, "*")
But you can even omit the loop:
F1 = 0.1:0.01:1;
f1 = F1 * fs;
f2 = (F1 - 0.001) * fs;
plot(f1, f2, "*")
  댓글 수: 1
Steven Lord
Steven Lord 2023년 2월 8일
Another option is to create an animatedline before the loop and addpoints to it inside the loop. Uncomment the pause statement or add some form of drawnow when running if you want to see the animation.
x = 0:360;
axis([0 360 -1 1])
hold on
h = animatedline;
for nextPoint = x
addpoints(h, nextPoint, sind(nextPoint))
% pause(0.01)
end

댓글을 달려면 로그인하십시오.

카테고리

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

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by