How to plot this for loop?

1 次查看(过去 30 天)
Nick Kavouris
Nick Kavouris 2020-10-11
回答: Ameer Hamza 2020-10-11
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

回答(1 个)

Ameer Hamza
Ameer Hamza 2020-10-11
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)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by