Borrar filtros
Borrar filtros

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

3 visualizaciones (últimos 30 días)
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 comentario
Dyuman Joshi
Dyuman Joshi el 6 de Jul. de 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?

Iniciar sesión para comentar.

Respuesta aceptada

Cris LaPierre
Cris LaPierre el 6 de Jul. de 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

Más respuestas (0)

Categorías

Más información sobre Stress and Strain en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by