Why wont my code plot anything
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
james Green
el 23 de Mzo. de 2022
Comentada: Voss
el 23 de Mzo. de 2022
clear
for n = 1:10
e = 1/factorial(n);
end
disp('calculated value for e = ')
disp(e)
percent_error = e/exp(1)*100
plot(1:10,e)
0 comentarios
Respuesta aceptada
Voss
el 23 de Mzo. de 2022
It doesn't appear to plot because e is a scalar. e is a scalar because it's overwritten each time through the loop.
Instead, make e a vector, one element of which is calculated each time through the loop. Then the plot will show up:
clear
for n = 1:10
% e = 1/factorial(n);
e(n) = 1/factorial(n);
end
disp('calculated value for e = ')
disp(e)
percent_error = e/exp(1)*100
plot(1:10,e)
2 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
