I am trying to use if statements to compare two vectors to get a value from a third. I need to display which months of one vector are higher than another then give the months that they are within .2 of each other.

1 回表示 (過去 30 日間)
WSFO =[6.7 7.5 8.5 9.5 10.4 10.9 11.2 10.5 9.1 7.6 6.3 6.5];
WOrl =[9.0 9.6 9.9 9.4 8.8 8.0 7.3 7.2 7.7 8.6 8.6 8.5];
Month={'Jan' 'Feb' 'Mar' 'Apr' 'May' 'Jun' 'Jul' 'Aug' 'Sep' 'Oct' 'Dec'};
A = mean(WSFO);
B = mean(WOrl);
fprintf(['\nThe average annual wind speed in San Francisco was (mph)'...
'\n %f\n'], A);
fprintf(['\nThe average annual wind speed in Orlando was'...
'(mph)\n %f\n'], B);
C = round(sum(WSFO<A));
D = round(sum(WOrl<B));
fprintf(['\nWind speed is below the annual average in San Francisco' ...
' for \n %f months\n'], C);
fprintf(['\nWind speed is below the annual average in Orlando for'...
'\n %f months\n'], D);
E = sum(WSFO > WOrl);
fprintf(['\nWind speed in San Francisco higher than in Orlando '...
'during the %d months of\n'], E);
if WSFO > WOrl
fprintf('%s %s\n',E, Month{1:2:3:4:5:6});
end
F = abs(WSFO - WOrl) <= .2;
if abs(WSFO - WOrl) <= .2
fprintf(['\nWind speed in San Francisco is within ±0.2mph of that in '...
'Orlando during the %d months of\n'], Apr);
end

採用された回答

KSSV
KSSV 2017 年 10 月 23 日
編集済み: KSSV 2017 年 10 月 23 日
WSFO =[6.7 7.5 8.5 9.5 10.4 10.9 11.2 10.5 9.1 7.6 6.3 6.5];
WOrl =[9.0 9.6 9.9 9.4 8.8 8.0 7.3 7.2 7.7 8.6 8.6 8.5];
Month={'Jan' 'Feb' 'Mar' 'Apr' 'May' 'Jun' 'Jul' 'Aug' 'Sep' 'Oct' 'Dec'};
A = mean(WSFO);
B = mean(WOrl);
fprintf(['\nThe average annual wind speed in San Francisco was (mph)'...
'\n %f\n'], A);
fprintf(['\nThe average annual wind speed in Orlando was'...
'(mph)\n %f\n'], B);
C = round(sum(WSFO<A));
D = round(sum(WOrl<B));
fprintf(['\nWind speed is below the annual average in San Francisco' ...
' for \n %f months\n'], C);
fprintf(['\nWind speed is below the annual average in Orlando for'...
'\n %f months\n'], D);
%%%%%
E = sum(WSFO > WOrl);
fprintf(['\nWind speed in San Francisco higher than in Orlando '...
'during the %d months of\n'], E);
idx = WSFO > WOrl ;
if E ~= 0
fprintf([repmat('%s,',1,E),'\n'], Month{idx});
end
F = abs(WSFO - WOrl) <= .2;
if abs(WSFO - WOrl) <= .2
fprintf(['\nWind speed in San Francisco is within ±0.2mph of that in '...
'Orlando during the %d months of\n'], Apr);
end
  3 件のコメント
KSSV
KSSV 2017 年 10 月 23 日
Edited the answer......I changed one condition, you do the other one.
Michael Johnson
Michael Johnson 2017 年 10 月 23 日
That was perfect. Thank you. I got the second part after changing what I needed.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePsychology についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by