Borrar filtros
Borrar filtros

How can I plot multiple results from a function on the same graph?

2 visualizaciones (últimos 30 días)
Aaron
Aaron el 17 de Dic. de 2013
Editada: Image Analyst el 18 de Dic. de 2013
Hello everyone,
I'm working on a Windchill conversion assignment, any guidance would be highly appreciated.
I want to display each result from the function (windchill_calc) - which takes a pre-defined temperature vector and a user inputted vector (of 5) and works out windchill (W_2)
Except the plot is only showing the result from the 5th value of the vector, I understand why this is happening and that this is quite a simple error but I can't work out a solution - any ideas?
(temp_vector is previously defined)
_______________________
windspeed_user = input('please enter a 5 windspeed vector'); %requesting input from user.
i = 1;
for i = 1:1:5;
W_2 = Windchill_calc(temp_vector, windspeed_user(i)) %calls function
end
plot (W_2, temp_vector)
xlabel ('Temperature (Fahrenheit)')
ylabel ('Windchill results')
grid on

Respuestas (2)

David Sanchez
David Sanchez el 17 de Dic. de 2013
I guess you have to work a bit with your data, but the hold on, hold off is what you need:
windspeed_user = input('please enter a 5 windspeed vector'); %requesting input from user.
i = 1;
for i = 1:5;
W_2 = Windchill_calc(temp_vector, windspeed_user(i)) %calls function
hold on
plot (W_2, temp_vector)
end
hold off
xlabel ('Temperature (Fahrenheit)')
ylabel ('Windchill results')
grid on
  1 comentario
Aaron
Aaron el 17 de Dic. de 2013
Editada: Image Analyst el 18 de Dic. de 2013
Yeah your right I do - I'm now trying to embellish a little, do you know why this if statement isn't working? (I want to limit the amount of values user inputs)
This is the result after adding the 'hold' feature, thank you for your fast reply.

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 17 de Dic. de 2013
Each iteration of the loop, you are over-writing all of W_2, so at the end of the loop only the final assignment has had any effect.
It appears to me that your W_2 would be a vector. If so, then
for i = 1 : 5
W_2 = Windchill_calc(temp_vector, windspeed_user(i)) %calls function
plot(temp_vector, W_2);
hold on
end
  2 comentarios
Aaron
Aaron el 17 de Dic. de 2013
Mm, that exactly what was happening - because as you said its the last result stored.
The hold function solved it instantly, :). Thankyou for your help and quick reply.
Walter Roberson
Walter Roberson el 17 de Dic. de 2013
Notice I also switched W_2 and temp_vector, as the independent variable should go first in the plot()

Iniciar sesión para comentar.

Categorías

Más información sobre Graphics Performance en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by