
How can I plot the results for a for loop?
1 回表示 (過去 30 日間)
古いコメントを表示
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!
0 件のコメント
採用された回答
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 件のコメント
その他の回答 (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!