Plot a Line of best fit onto a previously made graph that contains subplots

3 次查看(过去 30 天)
I graph stress vs strain earlier in my code just to verify the data looks good, later on I want to add a line of best fit over the small linear region before failure onto either the same figure or a new figure (either way I want to have stress vs strain and the corresponding line of best fit on one graph).
%% Graph Stress vs Strain
figure(2)
for k=1:n
subplot(1,n,k)
x = epsilon{1,k};
y = sigma{1,k};
plot(x,y,'.')
title('Stress vs Strain'),xlabel('Strain (%)','FontWeight','bold'),ylabel('Stress (MPa)','FontWeight','bold')
end
Above is the code for the stress vs strain graph
below is the code i currently have to try to graph the line of best fit on the same figure
figure(2)
for k=1:n
x = cut_epsilon{1,k}(1:end,1);
hold on
subplot(1,n,k)
plot(x, (slope(k)*x+intercept(k)), 'color','magenta' )
hold off
end
  1 个评论
Dyuman Joshi
Dyuman Joshi 2023-7-6
"(either way I want to have stress vs strain and the corresponding line of best fit on one graph)"
Why not merge the two for loops together?

请先登录,再进行评论。

采纳的回答

Cris LaPierre
Cris LaPierre 2023-7-6
You must make the axes current first, then turn hold on.
subplot(m,n,p) ... If axes exist in the specified position, then this command makes the axes the current axes.
Try modifying the code in your second loop to this (untested)
figure(2)
for k=1:n
x = cut_epsilon{1,k}(1:end,1);
subplot(1,n,k)
hold on
plot(x, (slope(k)*x+intercept(k)), 'color','magenta' )
hold off
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Stress and Strain 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by