Undefined function 'eq' for input arguments of type 'cell'. Undefined function 'gt' for input arguments of type 'cell'

28 views (last 30 days)
I have two double values obtained from a double matrix of size M X N. Now I want to compare these two values by == , > and < operators. But on running it is giving me the following errors.
Undefined function 'eq' for input arguments of type 'cell'
Undefined function 'gt' for input arguments of type 'cell'.

Answers (2)

KSSV
KSSV on 8 Feb 2021
There is no eq, gt in MATLAB; instead of that you need to use ==, >.
Example:
A = rand(10) ;
B = rand(10) ;
idx1 = A == B ; % equate
idx2 = A < =B ; % less than or equalto
idx3 = A >= B ; % graeter than or equal to
The above idx gives you logical indexing.
  3 Comments
KSSV
KSSV on 8 Feb 2021
Be it a scalar or a matix, it is same.
A = 2 ;
B = 3 ;
A==b % it will give 0
A<=B % it will showup 1 (true)
A>B % it will show up 0 (false)
Stephen23
Stephen23 on 8 Feb 2021
Edited: Stephen23 on 8 Feb 2021
"There is no eq, gt in MATLAB"
Actually there are:
" instead of that you need to use ==, >."
That is incorrect, those functions work perfectly:
gt(3,2)
ans = logical
1
eq(3,3)
ans = logical
1
Any experienced MATLAB user knows that all arithmetic operators, logical comparisons, concatenation operators, etc. are just syntactic sugar for the (quite possibly overloaded) functions which are actually called. This is an important principal of MATLAB that all beginners should learn.
In any case, this totally incorrect answer does not explain the cause of this error.
Reading the error message tells us what the actual problem is (hint: cell arrays).

Sign in to comment.


Stephen23
Stephen23 on 8 Feb 2021
Edited: Stephen23 on 8 Feb 2021
@ASHU DAYAL CHAURASIYA: the error message clearly tells us what the cause of the error is: one (or both) of the arrays is actually a cell array. Logical comparisons are not defined for cell arrays, thus the error:
A = [1,2,3]; % numeric array
B = [4,5,6]; % numeric array
C = {1,2,3}; % cell array
A>B % okay
ans = 1x3 logical array
0 0 0
B>C % error!
Operator '>' is not supported for operands of type 'cell'.
Possibly you will need to get the data out of the cell array before comparing it:
The correct way to make this comparison depends on how the data is organised, which so far you have not told us.

Categories

Find more on Structures in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!