필터 지우기
필터 지우기

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