Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Could I put this in a loop?

4 vues (au cours des 30 derniers jours)
Matthew Covington
Matthew Covington le 27 Fév 2019
Clôturé : MATLAB Answer Bot le 20 Août 2021
This is the following code I have
% PART C
% use find() and length() to determine how many months of each year exceed overall average
year2013 = find(lake_powell(:,1) > overall_average);
year2014 = find(lake_powell(:,2) > overall_average);
year2015 = find(lake_powell(:,3) > overall_average);
year2016 = find(lake_powell(:,4) > overall_average);
months2013 = length(year2013);
months2014 = length(year2014);
months2015 = length(year2015);
months2016 = length(year2016);
% print part C
fprintf('\nPART C: Determine how many months of each year > overall average')
fprintf('\n During 2013 the lake was above average for %2.0f months', months2013)
fprintf('\n During 2014 the lake was above average for %2.0f months', months2014)
fprintf('\n During 2015 the lake was above average for %2.0f months', months2015)
fprintf('\n During 2016 the lake was above average for %2.0f months\n', months2016)
This is the correct output, however is there a simpler way to do this and get the same output? My professor says I can only use the length and find functions to get the values.
PART C: Determine how many months of each year > overall average
During 2013 the lake was above average for 1 months
During 2014 the lake was above average for 7 months
During 2015 the lake was above average for 9 months
During 2016 the lake was above average for 12 months
  5 commentaires
Matthew Covington
Matthew Covington le 27 Fév 2019
This is what I had in my code at first then I wanted to make it shorter and cleaner so I tried to make it into a loop. However I could not figure out how to match up the code where it will display the correct output with the restrictions I am given.
Walter Roberson
Walter Roberson le 27 Fév 2019
Use years(n) in your fprintf()

Réponses (0)

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by