フィルターのクリア

max function in a for loop

7 ビュー (過去 30 日間)
Orion
Orion 2015 年 2 月 23 日
コメント済み: Orion 2015 年 2 月 23 日
Are we not allowed to use max function in a for loop? I have a 25x50 cell array A, and each element of A is a vector of various lengths.
for j=1:25
temp=cell2mat(A{j,20});
[max,ind]=max(temp);
m(j)=max;
end
the length of the vector "temp" is different at each loop. at the second loop I get this error even though I can see a value in the Max column of workspace for temp.:
Subscript indices must either be real positive integers or logicals.
and it messes up the whole software because then I try:
>> xx=1:10;
>> max(xx)
Index exceeds matrix dimensions.
Does anyone know what is wrong? Thanks

採用された回答

Image Analyst
Image Analyst 2015 年 2 月 23 日
You've used max as the name of your variable. DON'T DO THAT!!!!!!!! You've just blown away the max() function and now it thinks max is your array instead of the function.
for j=1:25
temp = A{j,20}; % cell2mat is not necessary unless A has another cell inside it.
[maxValue(j), indexOfMax] = max(temp(:));
end
  1 件のコメント
Orion
Orion 2015 年 2 月 23 日
Oops! my bad... thanks

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by