Using ismember with cell arays, R2010
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Erik From
am 11 Nov. 2020
Kommentiert: Erik From
am 11 Nov. 2020
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'
I used the example in https://se.mathworks.com/help/matlab/ref/double.ismember.html
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 = 1x4 logical array
0 1 0 1
Locb = 1×4
0 2 0 4
What key detail have I missed?
0 Kommentare
Akzeptierte Antwort
Steven Lord
am 11 Nov. 2020
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)
Compare the above with:
groceries = {'apple', 'banana', 'chicken', 'milk', 23.55};
fruit = {'apple', 'banana'};
ismember(groceries, fruit)
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Calendar finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!