fprintf in a loop

2 ビュー (過去 30 日間)
Matthew Covington
Matthew Covington 2019 年 2 月 27 日
編集済み: Matthew Covington 2019 年 2 月 27 日
I have the following code, I am trying to make the first %d change from 2013-2016 but cannot figure out the right way to put it. I've tried many things, please help.
n = 1;
years = 2013:2016
while n < 5
year = find(lake_powell(:,n) > overall_average);
months = length(year);
n = n + 1;
fprintf('\n During %d the lake was above average for %d months', years, months)
end
  1 件のコメント
madhan ravi
madhan ravi 2019 年 2 月 27 日
We don’t have the data to run your code , forgot to mention how does the currecnt result differ from your expected result.

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

回答 (1 件)

Geoff Hayes
Geoff Hayes 2019 年 2 月 27 日
Matthew - you could use a for loop instead
years = 2013:2016
for k = 1:length(years)
% your code
fprintf('\n During %d the lake was above average for %d months', years(k), months)
end
You may wish to rename your year variable to make it more clear what it represents (the months of the year that the lake height?volume? was above average)....so as not to confuse it with years.

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by