Plots using for loops

4 visualizaciones (últimos 30 días)
Zoe Westcott
Zoe Westcott el 10 de Jun. de 2022
Comentada: Zoe Westcott el 10 de Jun. de 2022
This is my text, i want do a loglog plot for error which is my function Ptoject_example3 against h, but wheneber I run the code doesnt plot anything.
m=1;
for h=0.01:0.01:0.1
error = Project_example3(h,m);
end
h=0.01:0.01:0.1;
figure;
loglog(error,h)

Respuesta aceptada

KSSV
KSSV el 10 de Jun. de 2022
Editada: KSSV el 10 de Jun. de 2022
Your code saves, only one value for error, which happens to be the last value of the loop. You need to save error into an array and then plot.
m=1;
h=0.01:0.01:0.1;
error = zeros(size(h)) ;
for i = 1:length(h)
error(i) = Project_example3(h(i),m);
end
figure;
loglog(error,h)
  1 comentario
Zoe Westcott
Zoe Westcott el 10 de Jun. de 2022
Thank you, helped very much

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by