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 visualizaciones (últimos 30 días)
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

Respuesta aceptada

KSSV
KSSV el 23 de Oct. de 2017
Editada: KSSV el 23 de Oct. de 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 comentarios
KSSV
KSSV el 23 de Oct. de 2017
Edited the answer......I changed one condition, you do the other one.
Michael Johnson
Michael Johnson el 23 de Oct. de 2017
That was perfect. Thank you. I got the second part after changing what I needed.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Psychology en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by