How to correct for 'Undefined function 'eq' for input arguments of type 'cell'' error message
Show older comments
Hi,
I have a simple bit of code and keep getting an error message,
>>
for Area = 1:652
if Area == out(:,1)
DateofB = out(:,2)
LocationSquare(Area) = DateofB
end
end
Undefined function 'eq' for input arguments of type 'cell'.
I've tried using curled braces instead in my if statement but that doesn't work.
I've also tried using an isequal term instead too but it doesn't like that either.
Am I going about this in the wrong way?
Thanks for any help, advice, direction that can be spared.
6 Comments
B.k Sumedha
on 7 Aug 2015
In which line are u getting the error?
Chameleon17
on 9 Aug 2015
Walter Roberson
on 9 Aug 2015
You have Area == out(:,1) . That makes it appear that you would be comparing a particular value to a vector of values. When you "if" something that is a vector of values, the result is only considered true if all of the values are considered true. Is that your intention, or did you want the comparison to succeed if any one of them is true, like any(Area == out(:,1)) ? Or do you need to know which of them is true?
Chameleon17
on 11 Aug 2015
Edited: Walter Roberson
on 11 Aug 2015
Chameleon17
on 11 Aug 2015
Answers (2)
Matt J
on 7 Aug 2015
I've tried using curled braces instead in my if statement but that doesn't work.
See what you get when you do the following,
>> A={1,2,3};
>> if A{1}==1, disp 'Hello World', end
Hello World
>> if A==1, disp 'Hello World', end
Undefined operator '==' for input arguments of type 'cell'.
Walter Roberson
on 11 Aug 2015
indices = cell2mat(out(:,1));
LocationSquare(indices) = out(indices,2);
No loop.
Note: this relies upon out(:,1) always being valid and unique.
4 Comments
Chameleon17
on 12 Aug 2015
Walter Roberson
on 12 Aug 2015
If the second part refers to the second line then it has nothing to do with the second column being in date string format. But I should probably have coded the right side as out(:, 2)
I predict that at least one of your column 1 values is 0 or negative or nan or inf or non-integral. Not a valid index in other words. My speculation is that you have some 0 in there that are intended to indicate that the second column is not to be placed anywhere.
Chameleon17
on 12 Aug 2015
Chameleon17
on 12 Aug 2015
Categories
Find more on Logical 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!