How to plot this for loop?

for i=0:0.01:1;
CompMod=(Gmodulus*i)+(Emodulus*(1-i));
end
plot(i,CompMod)
How do I plot this simple code? Gmod and Emod have been previously indexed

Respuestas (1)

Ameer Hamza
Ameer Hamza el 11 de Oct. de 2020

0 votos

You need to save the values from each iteration in an array. Check this code
Gmodulus = 1; % example values
Emodulus = 2;
x = 0:0.01:1;
CompMod = zeros(size(x));
for i = 1:numel(x)
CompMod(i) = (Gmodulus*x(i))+(Emodulus*(1-x(i)));
end
plot(x,CompMod)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Productos

Versión

R2018a

Etiquetas

Preguntada:

el 11 de Oct. de 2020

Respondida:

el 11 de Oct. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by