How can I plot the results for a for loop?

조회 수: 1 (최근 30일)
Nightowl
Nightowl 2015년 4월 13일
편집: Stephen23 2015년 4월 14일
Hi,
I'm very new to matlab and I can't figure this out!
I need to write a for loop changing a single variable. I need to plot the results for each variable value. This is what I have so far
u=2.5
o=0.15
d=0:0.1:10
PSD=(1/(o*((2*pi)^0.5)))*exp(-((d-u).^2)/(2*o^2))
kc=0.865
for i=1:3
dc(i)=i
Td=1-exp(-kc*(d./dc(i)).^2)
Solremoval=(sum(Td.*PSD)/sum(PSD))*100
plot(Solremoval,dc)
end
Please help!

채택된 답변

Stephen23
Stephen23 2015년 4월 13일
편집: Stephen23 2015년 4월 14일
You should not use the variable names i and j as these are both names of the inbuilt imaginary unit. You might also like to place a semicolon after each line to prevent them printing to the command window.
Although figuring out non-functioning code is a little bit of a guessing game, this seems to prduce a similar result to what you are trying to do, via the very handy helper-function bsxfun and without any loops at all:
u = 2.5;
o = 0.15;
d = (0:0.1:10).';
PSD = (1/(o*((2*pi)^0.5)))*exp(-((d-u).^2)/(2*o^2));
kc = 0.865;
dc = 1:3;
Td = 1 - exp(-kc*bsxfun(@rdivide,d,dc).^2);
Solremoval = 100*sum(bsxfun(@times,Td,PSD))/sum(PSD);
plot(Solremoval,dc,'*-')
This produces the following figure:

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by