필터 지우기
필터 지우기

how to plot curve using data from for loop

조회 수: 1 (최근 30일)
Roman Barancin
Roman Barancin 2013년 4월 9일
i need help with plotting this equation using for loop. I found solution already posted here, but i wasnt able to implement it on my problem. (Currently this will plot only one dot (i assume thats the last value from for loop)
for K = [1 2 3 4 5]
Q=0.49;
Rac=0.0015;
m=K;
freq=(K*9000);
Cr=1/(2*pi*Q*freq*Rac);
Lr=1/(((2*pi*freq)^2)*Cr);
Lp=m*Lr;
w=2*pi*freq;
w0=1/(sqrt(Lr*Cr));
wp=1/(sqrt(Lp*Cr));
Race=14685.973;
Qe=(sqrt(Lr/Cr))*(1/Race);
%///////////////////////////////////////
citatel=((w^2)/(w0^2).*(sqrt(m.*(m-1))));
menovatel=(((w^2)/((wp^2))-1)+1i.*(w/w0).*(((w^2)/(w0^2))-1).*(m-1).*Qe);
gain=(citatel/menovatel);
plot(freq,gain);
end

채택된 답변

Jan
Jan 2013년 4월 9일
Either insert hold('on') bevor the loop, such that the plot() command does not delete formerly existing points. Or collect the data at first and draw them after the loop as a line:
freqV = zeros(1, 5);
gainV = zeros(1, 5);
for K = 1:5
... % No changes here
% Instead of:
% plot(freq,gain);
freqV(K) = freq;
gainV(K) = gain;
end
plot(freqV, gainV);

추가 답변 (1개)

Tobias
Tobias 2013년 4월 9일
Change your freq and gain variables, so they're both a function of k. All values will be stored that way and your plot should work. The syntax is:
freq(K) = (K*9000);
gain(K) = (citatel/menovatel);

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by