Using "for loop" in MATLAB to finish this problem?

조회 수: 9 (최근 30일)
john doe
john doe 2016년 11월 11일
편집: Walter Roberson 2016년 11월 13일
The problem is below. They ask for basically 2 vectors and to use a for loop to check each element and add to get the total precipitation for part a) for example. Can any of you guys help me out? I had the program I wrote adding the elements in part a), but it was not giving me the total precipitation, only the total sum of the elements. If you guys could help me with a, b, or part C, I would be insanely grateful!
*"The average monthly precipitation (in.) for Boston and Seattle during 2012 are given in the vectors below (data from the U.S. National Oceanic and Atmospheric Administration).
BOS=[2.67 1.00 1.21 3.09 3.43 4.71 3.88 3.08 4.10 2.62 1.01 5.93]
SEA=[6.83 3.63 7.20 2.68 2.05 2.96 1.04 0.00 0.03 6.71 8.28 6.85]
Where the elements in the vectors are in the order of the months (January, February, etc.) Write your program to answer the following:
(a) Calculate the total precipitation for the year and monthly average precipitation in each city. Do NOT use MATLAB’s built-in functions sum and mean. (b) How many months was the precipitation above the average in each city? (c) How many months, and on which months, was the precipitation in Boston lower than the precipitation in Seattle?"*

답변 (1개)

Deen Halis
Deen Halis 2016년 11월 12일
편집: Walter Roberson 2016년 11월 13일

Hi John, you can try this for a) Boston as an example

 BOS=[2.67 1.00 1.21 3.09 3.43 4.71 3.88 3.08 4.10 2.62 1.01 5.93];
t_bos = 0;
for i1 = 1:numel(BOS)
      t_bos = t_bos + BOS(i1);
      m_bos(i1) = t_bos;
  end
  m_bos

카테고리

Help CenterFile Exchange에서 Climate Science and Analysis에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by