Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Plotting using a for loop

1 visualización (últimos 30 días)
Fraser Brooker
Fraser Brooker el 26 de Oct. de 2020
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
I'm having trouble with plotting a graph when using a for loop to generate the values.
x = 0: 0.1 : 1.4
for x = 0:0.1:1.4
y = iteration2shear(x)
end
plot(x,y)
hold on
The function I'm calling generates the correct values for each value of y, but im struggling to generate a plot to illustrate it.

Respuestas (2)

Rik
Rik el 26 de Oct. de 2020
You are forgetting to index your y variable. In general it is easier to write your code like this in such cases:
x = 0: 0.1 : 1.4;
y=zeros(size(x));
for n=1:numel(x)
y(n) = iteration2shear(x);
end
plot(x,y)

Jon
Jon el 26 de Oct. de 2020
You need to save your values to a vector you are just replacing a single scalar value
  1 comentario
Jon
Jon el 26 de Oct. de 2020
I see that by the time I answered your question Rik had also given you a good answer

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by