Why is my plot() not working?

조회 수: 7 (최근 30일)
Hyunji Park
Hyunji Park 2022년 2월 21일
댓글: Star Strider 2022년 2월 21일
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])

답변 (1개)

Star Strider
Star Strider 2022년 2월 21일
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
Hyunji Park
Hyunji Park 2022년 2월 21일
I see it now, thank you!
Star Strider
Star Strider 2022년 2월 21일
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Stress and Strain에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by