Effacer les filtres
Effacer les filtres

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 vues (au cours des 30 derniers jours)
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 commentaires
tina jain
tina jain le 11 Avr 2015
if I make change at line 3 i.e. marge=max{t}; then the error changes to Undefined variable max.
James Tursa
James Tursa le 11 Avr 2015
Why are you trying to find the max of a cell array? What would you expect the output to be?

Connectez-vous pour commenter.

Réponses (1)

Stephen23
Stephen23 le 11 Avr 2015
Modifié(e) : Stephen23 le 11 Avr 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.

Catégories

En savoir plus sur Numeric Types dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by