2つの行列の列をsame datatype
に変換して、ismember
を実行する必要があります。 1つの列は行列[]
形式であり、もう1つは文字列形式です。つまり、[2000]
と'2000'
を一致させる必要があります。参照してください:MATLABのcell2mat変換(ismemberの場合)
mat1 = {'aa' [2001] ; 'ex' [10] ; 'ex' [1001] ; 'rt' [4001] ;} ;
mat2 = {'abc' '10' ; 'def' '4001' ; 'ghi' '2001' ; } ;
ismember(cell2mat(mat1(:,2)), cell2mat(mat2(:,2))) % Gives ERROR
%cell2mat(mat1(:,2) works just fine
%cell2mat(mat2(:,2)) is the PROBLEM.
%Final answer
ans = {...
'aa' [2001] 'ghi'; 'ex' [10] 'abc'; 'ex' [1001] 'abc'; 'rt' [4001] 'def';} ;
可能であれば、ベクトル化コードを理解してください。