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.

2 visualizzazioni (ultimi 30 giorni)
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);

Risposte (1)

Stephen23
Stephen23 il 11 Apr 2015
Modificato: Stephen23 il 11 Apr 2015
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.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by