필터 지우기
필터 지우기

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 CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by