I am trying to calculate the Wind Chill factor for many values of Wind speed and Temp.
I want to only use values when TEMP is less than 50 and wind speed is greater than 3.
I also need the result to be a vector so I can plot all the values. Below us my code
Note that I am reading my wind and tempo values from an excel file. Thanks!
for n=1:length(TEMP)
if TEMP<50 && WIND>3
TEMP=dlmread('denver_weather.csv',',',[7,5,0,5]);
WIND=dlmread('denver_weather.csv',',',[7,12,0,12]);
WCF(n)=35.7+0.6.*TEMP-35.7.*(WIND.^(.16))+.43.*(WIND.^(.16))
end
end

 Réponse acceptée

Star Strider
Star Strider le 8 Fév 2017
You didn’t attach ‘denver_weather.csv’ so I can only assume ‘TEMP’ and ‘WIND’ are equal-size vectors.
I would do something like this:
TEMP = dlmread('denver_weather.csv',',',[7,5,0,5]);
WIND = dlmread('denver_weather.csv',',',[7,12,0,12]);
idx = TEMP<50 & WIND>3; % Logical Index
WCF = 35.7+0.6.*TEMP(idx)-35.7.*(WIND(idx).^(.16))+.43.*(WIND(idx).^(.16));
NOTE This is obviously UNTESTED CODE. If my assumptions are correct, it should work with minimal modification.

2 commentaires

Mitch White
Mitch White le 8 Fév 2017
Modifié(e) : Mitch White le 8 Fév 2017
Thanks! If I need the WCF array to be the same size to plot against a corresponding date/time, how would I incorporate the days/time when the WCF is zero so that my arrays match up?
My date/time array is the same size as the TEMP and WIND arrays
Star Strider
Star Strider le 8 Fév 2017
My pleasure!
I would use the ‘idx’ logical vector to select the date/time array just as with the others. They will all then have the same lengths and will correspond so you can plot them.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Mathematics dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by