Clear Filters
Clear Filters

Plotting using a for loop

1 view (last 30 days)
alexrecai
alexrecai on 19 Mar 2021
Commented: alexrecai on 19 Mar 2021
Hello, I'm having a difficulty plotting the results using a for loop. I want to plot epsilon vs sigma but I get the following error: Array indices must be positive integers or logical values. Can you please help me? Thank you.
E=200*10^9; %Pa Elastic Modulus
v= 0.28; %Poisson's Ratio
eps=linspace(0,0.1,1000);
Y= 375.8;
m=2000;
n=0.5;
for i= 1:1000
sigma(i)=Y(1+m*eps(i)^n)
end
eps=[0 eps];
plot(eps,sigma)

Accepted Answer

Alan Stevens
Alan Stevens on 19 Mar 2021
Like so:
E=200*10^9; %Pa Elastic Modulus
v= 0.28; %Poisson's Ratio
eps=linspace(0,0.1,1000);
Y= 375.8;
m=2000;
n=0.5;
for i= 1:1000
sigma(i)=Y*(1+m*eps(i)^n); % You need a multiply sign between Y and what follows it.
end
% eps=[0 eps]; You don't need this.
plot(eps,sigma)
  1 Comment
alexrecai
alexrecai on 19 Mar 2021
Oh, I didn't notice that. Thank you very much!

Sign in to comment.

More Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!