I am having an issue with this code. I am trying to use plot this and it only comes up with a blank graph. I tried moving the plot command outside the loop but it messes up the numbers on my axes and still doesn't plot.
hold on;
for i = 0:15
v_perp = 6*cosd(i)+7*sind(i);
percent_perp = (abs(v_perp)/14)*100;
plot(i,percent_perp)
end

 Respuesta aceptada

Walter Roberson
Walter Roberson el 30 de Sept. de 2017

0 votos

Using the more general pattern that does not require that the i values be integers at all:
i_vals = 0:15;
for i_idx = 1 : length(i_vals)
i = i_vals(id_idx);
v_perp = 6*cosd(i)+7*sind(i);
percent_perp(i_idx) = (abs(v_perp)/14)*100;
end
plot(i_vals, percent_perp)
In the particular case of i being integer and starting from 0, this can be abbreviated to
for i = 0:15
v_perp = 6*cosd(i)+7*sind(i);
percent_perp(i+1) = (abs(v_perp)/14)*100;
end
plot(0:15, percent_perp)

1 comentario

Anne Coleman
Anne Coleman el 30 de Sept. de 2017
I did integer case and it worked. Thank you!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Graphics Objects en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 30 de Sept. de 2017

Comentada:

el 30 de Sept. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by