How can I plot the results for a for loop?

1 visualización (últimos 30 días)
Nightowl
Nightowl el 13 de Abr. de 2015
Editada: Stephen23 el 14 de Abr. de 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!

Respuesta aceptada

Stephen23
Stephen23 el 13 de Abr. de 2015
Editada: Stephen23 el 14 de Abr. de 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:

Más respuestas (0)

Categorías

Más información sobre Graphics Performance en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by