フィルターのクリア

How to read in, compare and then delete data from a cellarray?

1 回表示 (過去 30 日間)
J
J 2015 年 9 月 3 日
コメント済み: Star Strider 2015 年 9 月 4 日
Hi,
How do I filter cellarray A to only return the unique values (i.e. in this example A319, A320, A321) once, then compare these unique values against a structure, B, removing any rows from B which do not contain the unique values from A? Example below:
I'm looking for a general solution as the values contained in A can change. Structure B will not change but I have reduced the size of it for example purposes only.
>> A
A =
'A319'
'A319'
'A320'
'A320'
'A319'
'A320'
'A321'
'A320'
B = 'A306' 'A300B4-' 'non-metric' 'jet'
'A30B' 'A300B4-' 'non-metric' 'jet'
'A310' 'A310-20' 'non-metric' 'jet'
'A319' 'A319-13' 'non-metric' 'jet'
'A320' 'A320-21' 'non-metric' 'jet'
'A321' 'A321' 'non-metric' 'jet'
'A332' 'A330-24' 'non-metric' 'jet'
'A333' 'A330-30' 'non-metric' 'jet'
so B should return...
'A319' 'A319-13' 'non-metric' 'jet'
'A320' 'A320-21' 'non-metric' 'jet'
'A321' 'A321' 'non-metric' 'jet'
There are more columns (fields) in B, 101x15 to be exact.

採用された回答

Star Strider
Star Strider 2015 年 9 月 3 日
Assuming that ‘A’ is an (8x1) cell and ‘B’ is a (8x4) cell, this will work for this example. This appears to be robust, since ismember returns all matches:
Lia = ismember(B(:,1), A);
C = B(Lia,:);
  2 件のコメント
J
J 2015 年 9 月 4 日
編集済み: J 2015 年 9 月 4 日
Fantastic! The only thing I've changed is to make it work for a structure instead of a cellarray (as B is a structure)
Lia = ismember(B(:,1), A);
B = B(Lia);
Star Strider
Star Strider 2015 年 9 月 4 日
Thank you. (I didn’t know it was a structure.)

サインインしてコメントする。

その他の回答 (0 件)

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by