MATLAB: Loop for calculating wind chill values

while

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

Best Answer

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