max function does not work

3 ビュー (過去 30 日間)
Søren Schwartz
Søren Schwartz 2015 年 11 月 18 日
編集済み: Walter Roberson 2015 年 11 月 20 日
Hello
I am trying to use the max function, but it will not work. I have attached my log file.
I have tried using this function
maxStcev=max(Stcev'-K,0); %(line 52)
but I keep getting negative values.
I have then tried using a for loop with if statement, but this results in error:
"Index exceeds matrix dimensions.
Error in mccev (line 45)
if (M1(1,o)<0)"
Can someone see what I am doing wrong? I want t have a vector only with positive values.
Regards,
Søren
  1 件のコメント
Walter Roberson
Walter Roberson 2015 年 11 月 20 日
No file was attached

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

回答 (1 件)

Shruti Sapre
Shruti Sapre 2015 年 11 月 20 日
Hi Søren
I could not view the log file attached, and I am not very sure about the workflow taken by you. Generally, the "Index exceeds matrix dimensions" error occurs when elements outside the bounds of valid indices are being accessed. The variable "o" in the above example could be greater than the matrix dimension at some iteration in the loop. Please make sure it is within the matrix dimensions.
If you want to simply separate out the positive values from a vector, you could do something like:
>>x=[6 5 -2 3 -7]
>>y=x(x>0)
Hope this helps!
-Shruti

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by