Is there a way to use ISMEMBER to obtain specific rows of data in a cell array?

11 ビュー (過去 30 日間)
I'm attempting to use ISMEMBER in order to obtain specific rows of data in a cell array. The code I'm currently using is:
% Clear WS variables and the comand window
clear all;
% Create a pair of cell arrays of strings
C = ["20749";"20750";"20751"];
A = cellstr(C);
D = ["20749" "11" "ABC-21"; "1000" "35" "XYZ-54"; "20749" "113" "BXT MNT"; "20750" "400" "ABC-21"; "2000" "35" "ABC-01"; "20751" "42" "SRT-29"; "2001" "60" "ARN-21";"20750" "80" "ABC-21"; "20749" "25" "ABC-21"; "3000" "14" "ABC-21"];
B = cellstr(D);
% Array elements that are members of set array
[Lia,Locb] = ismember(A,B,'legacy');
I've run into a problem where Locb contains the lowest index in B for each value, instead of all the indices. Eventually I'd write the applicable rows of data in B into a separate variable. Is there a technique I could utilize that would allow for this? Or will I need to use a different function/technique?


Brad 2018 年 2 月 8 日
It appears I've answered my own question with the following solution;
E = B(ismember(B(:, 1), A), :);
  1 件のコメント
Dooyoung Kim
Dooyoung Kim 2018 年 9 月 5 日
It worked well for me. Thanks!


その他の回答 (0 件)



Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by