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 Center および File ExchangeStress and Strain についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by