Why is my plot() not working?

7 views (last 30 days)
Hyunji Park
Hyunji Park on 21 Feb 2022
Commented: Star Strider on 21 Feb 2022
Hello! I'm fairly new to MATLAB and I'm tryng out a simple code which should help me plot a stress-strain curve using user-input values. However, my plot() isn't appearing. Should I add or remove something from the code?
% User-input values for Strain
initial_l = input('Enter the initial length of the material in m: ');
change_l = input('Enter the elongation of the material in m: ');
% User-input values for Stress
load = input('Enter the load exerted on the material in N: ');
rad = input('Enter the radius of the material in m: ');
% Formulas for Strain
del_l = change_l - initial_l;
strain_x = change_l./ initial_l;
% Formulas for Stress
area = pi*rad^2;
stress_y = load./ area;
% Plotting of values
figure(1) % Stress-Strain Curve
plot(strain_x,stress_y)
x = strain_x;
y = stress_y;
xlabel('Strain')
ylabel('Stress')
hold on
grid on
axis([-1 1 -0.01 0.01])

Answers (1)

Star Strider
Star Strider on 21 Feb 2022
Experiment by commenting-out the axis call.
The values being plotted are outside the axes limits.
initial_l = 20;
change_l = 30;
load = 40;
rad = 50;
% Formulas for Strain
del_l = change_l - initial_l;
strain_x = change_l./ initial_l;
% Formulas for Stress
area = pi*rad^2;
stress_y = load./ area;
% Plotting of values
figure(1) % Stress-Strain Curve
plot(strain_x,stress_y, '-p')
x = strain_x;
y = stress_y;
xlabel('Strain')
ylabel('Stress')
hold on
grid on
% axis([-1 1 -0.01 0.01])
.
  2 Comments
Hyunji Park
Hyunji Park on 21 Feb 2022
I see it now, thank you!
Star Strider
Star Strider on 21 Feb 2022
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

Sign in to comment.

Categories

Find more on Stress and Strain in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!