Loop for calculating wind chill values

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

 采纳的回答

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 个评论

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
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.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Mathematics 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by