How to plot this for loop?

2 views (last 30 days)
Nick Kavouris
Nick Kavouris on 11 Oct 2020
Answered: Ameer Hamza on 11 Oct 2020
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

Answers (1)

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

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!