Azzera filtri
Azzera filtri

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

3 visualizzazioni (ultimi 30 giorni)
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 Commento
Dyuman Joshi
Dyuman Joshi il 6 Lug 2023
"(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?

Accedi per commentare.

Risposta accettata

Cris LaPierre
Cris LaPierre il 6 Lug 2023
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

Più risposte (0)

Categorie

Scopri di più su Stress and Strain in Help Center e File Exchange

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by