Function issues when user input is required for if statement?

1 回表示 (過去 30 日間)
Rachel McLaughlin
Rachel McLaughlin 2016 年 5 月 4 日
コメント済み: Rachel McLaughlin 2016 年 5 月 4 日
Hi all,
I am trying to write a function meant to address a table, where the user would specify whether they want to aggregate data by day/month/year and the output would be a summary table of that information. Right now I have:
function y = preciptotal(x)
Prompt = 'Are you totaling by Day, Month, or Year?';
UI = input(Prompt, 's');
if UI == 'Day';
y =varfun(@sum,x,'InputVariables','Rain_mm','GroupingVariables',{'Month' 'Day' 'Year'});
elseif UI == 'Month';
y =varfun(@sum,x,'InputVariables','Rain_mm','GroupingVariables',{'Month' 'Year'});
elseif UI == 'Year';
y =varfun(@sum,x,'InputVariables','Rain_mm','GroupingVariables',{'Year'});
end
end
The function runs fine when the UI is Day, but gets caught up when Month or Year are used. Any ideas why this may be?
Thanks!

採用された回答

Walter Roberson
Walter Roberson 2016 年 5 月 4 日
strcmp() not "=="
  1 件のコメント
Rachel McLaughlin
Rachel McLaughlin 2016 年 5 月 4 日
Ah, I should have figured that out. Thanks yet again!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by