I am having a lot of trouble with the built in mode function

2 ビュー (過去 30 日間)
AStar
AStar 2019 年 11 月 26 日
コメント済み: AStar 2019 年 11 月 26 日
I need to use the mode function to be able to calculate the mode of my data which is a large data set consiting of temperatures between 1984-2016 in Canada. In addition to this, I also use the mean function the min function and the max function on my data. For some reason however, the mode function is causing me a lot of trouble. The code runs perfectly until I ask matlab to calculate the mode. This is the error message I get
"Array indices must be positive integers or logical values."
I dont really understand what the problem is here because I can see the mode being calculate in my workspace and the values make sense, however the code seems to freeze when I ask it to calculate the mode and it doesnt proceed with the rest of my program. This is how ive been writing it in my code: Im calling column 8 because which is where I have the data I need.Can anyone explain what could be causing this problem? I also tried this feb_mode1=mode(double(:,8)); which appeared to be working at first and then it didnt work anymore. Thanks.
feb_mode1=mode(feb(:,8));

採用された回答

James Tursa
James Tursa 2019 年 11 月 26 日
編集済み: James Tursa 2019 年 11 月 26 日
You have inadvertently created a variable called "mode" that is shadowing the MATLAB mode( ) function. Track down where that is happening in your code and rename that variable to something else. E.g., to see this
which mode
  2 件のコメント
AStar
AStar 2019 年 11 月 26 日
If I type in which mode, matlab tells me mode is a variable. So its the case of what you were saying then? I have accidentaly shadowed the matlab mode?
AStar
AStar 2019 年 11 月 26 日
Thanks! It worked!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by