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

 채택된 답변

Star Strider
Star Strider 2017년 2월 8일

0 개 추천

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

Mitch White
Mitch White 2017년 2월 8일
편집: Mitch White 2017년 2월 8일
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 2017년 2월 8일
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에 대해 자세히 알아보기

태그

질문:

2017년 2월 8일

댓글:

2017년 2월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by