How can I plot the results for a for loop?

1 vue (au cours des 30 derniers jours)
Nightowl
Nightowl le 13 Avr 2015
Modifié(e) : Stephen23 le 14 Avr 2015
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!

Réponse acceptée

Stephen23
Stephen23 le 13 Avr 2015
Modifié(e) : Stephen23 le 14 Avr 2015
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:

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Performance dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by