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.

2 views (last 30 days)
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

Accepted Answer

KSSV
KSSV on 23 Oct 2017
Edited: KSSV on 23 Oct 2017
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 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on Psychology in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!