MATLAB: Using ismember with cell arays, R2010

2010ismember

Hi,
I have a matrix containing both letters and values. Example down below, very similar to the real one i used below. I have a nother vector saved as
M_Punkter = {'B76', 'B80', 'B83'};
My code for evaluating these is:
VAL=1
for i=1:length(M_Punkter)
Lia = ismember(raw{1,1}(:,1),M_Punkter(i));
VAL=VAL+1;
end
I get the error message
??? Error using ==> cell.ismember at 28
Input must be cell arrays of strings.
Error in ==> Bulleranalys_V3_ej_fin at 77
Lia = ismember(raw{1,1}(:,1),M_Punkter(i));
Note, it is not finished. Just testing phase to get the basics right
I understand that I have made something fundamentally wrong and read up on https://se.mathworks.com/help/matlab/ref/double.ismember.html
where they used cell arays. My raw file contains multilevel cell arays. And my results from raw{1,1}(:,1)
ans =
'Mätpunkt'
[NaN]
'B76'
'B76'
'B76'
'B76'
'B76'
'B76'
'B76'
'B76'
'B76'
[NaN]
[NaN]
[NaN]
and
M_Punkter(i)
ans =
'B76'
A = {'dog','cat','fish','horse'};
Create a cell array of character vectors, B, where some of the vectors have trailing white space.
B = {'dog ','cat','fish ','horse'};
Determine which character vectors of A are also in B.
[Lia,Locb] = ismember(A,B)
Lia = 1×4 logical array
0 1 0 1
Locb = 1×4
0 2 0 4
What key detail have I missed?

Best Answer

What key detail have I missed?
The fact that your raw cell array contains both text and numbers.
groceries = {'apple', 'banana', 'chicken', 'milk'};
fruit = {'apple', 'banana'};
ismember(groceries, fruit)
ans = 1x4 logical array
1 1 0 0
Compare the above with:
groceries = {'apple', 'banana', 'chicken', 'milk', 23.55};
fruit = {'apple', 'banana'};
ismember(groceries, fruit)
Error using cell/ismember (line 34)
Input A of class cell and input B of class cell must be cell arrays of character vectors, unless one is a character vector.
This is a different error message than you would receive if you ran this code in release R2010a or R2010b (we've changed it at least once in the ensuing ten years) but the root cause is the same. If you run the second example you'll see it gives you the same error as you posted.