I am executing the code below and getting the error " Undefined function 'max' for input arguments of type 'cell'" . Please help me to solve this.

조회 수: 1 (최근 30일)
function [T11,T22]=propp(t)
t=t(:)';
marge=max(t);
[s1,s]=size(t);
k=1;
T2=zeros(1,marge);
for i=1:s
T1(i)=i;
p=t(i);
T2(p)=T2(p)+1;
end
%T2=T2/s;
i=1;
while i<=marge
[p1,p2]=max(T2);
if p1==0
i=marge+1;
else
T11(i)=p2;
T22(i)=p1;
T2(p2)=0;
i=i+1;
end
end
output Undefined function 'max' for input arguments of type 'cell'. Error in propp (line 5) marge=max(t);
  댓글 수: 2
tina jain
tina jain 2015년 4월 11일
if I make change at line 3 i.e. marge=max{t}; then the error changes to Undefined variable max.
James Tursa
James Tursa 2015년 4월 11일
Why are you trying to find the max of a cell array? What would you expect the output to be?

댓글을 달려면 로그인하십시오.

답변 (1개)

Stephen23
Stephen23 2015년 4월 11일
편집: Stephen23 2015년 4월 11일
Read the documentation for max and find the section describing the input arguments. The input array A is listed as being any of the following data-types:
Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | categorical | datetime | duration
Can you see cell array listed there? And now look at the first five lines of your code:
function [T11,T22]=propp(t)
t=t(:)';
marge=max(t);
According to the error message the problem occurs on line five only when you supply t as a cell array. So if you supply t as a numeric array (one of the types listed by the documentation), then you will not get this error.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by