Reputation: 45
This code:
if (prefixTree(1,4).prefixTree2(:,2)=='2')
unique(prefixTree(1,4).prefixTree2(:,3))
end
returns this error:
Undefined function 'eq' for input arguments of type 'cell'.
Why?
Upvotes: 1
Views: 1105
Reputation: 18484
The error implies that prefixTree(1,4).prefixTree2(:,2)
is a cell array. You can access the individual elements of the second column with prefixTree(1,4).prefixTree2{:,2}
. Also, the colon operator implies that there is more than one element in prefixTree(1,4).prefixTree2(:,2)
but you're trying to do a scalar comparison. Lastly, you're comparing to a char
('2'
as opposed to the number 2
) and thus it would be best to use string functions. You can use strcmp
to check each element of your cell:
prefixTree(1,4).prefixTree2 = {'1' '2';'3' '2'}; % Example data
strcmp(prefixTree(1,4).prefixTree2(:,2),'2')
Then use any
or all
to return a scalar for your if
statement:
if all(strcmp(prefixTree(1,4).prefixTree2(:,2),'2'))
...
end
Upvotes: 5