Delete specific rows from a cell array

Hello everyone, i have a cell array just like this:
value Class
1200 'Unknown - State'
1700 'Rest'
1600 'Unknown - State'
2100 'City'
How i'm going to remove the rows whose class is 'Unknown-State' so my result cell array woulb be like this:
Value Class
1700 'Rest'
2100 'City'

 採用された回答

the cyclist
the cyclist 2014 年 12 月 14 日

1 投票

Assuming your cell array is name "C", then
removeIndex = strcmp(C(:,2),'Unknown - State');
C(removeIndex,:) = [];
If you don't know ahead of time that the class is the second column, then you could find the class column number using
classIdx = find(strcmp(C(1,:),'Class'))

1 件のコメント

Alex
Alex 2014 年 12 月 14 日
Thanks a lot cyclist :)

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

その他の回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 12 月 14 日

2 投票

a={1200 'Unknown - State'
1700 'Rest'
1600 'Unknown - State'
2100 'City'}
b=a(~ismember(a(:,2),'Unknown - State'),:)

3 件のコメント

Alex
Alex 2014 年 12 月 14 日
Thanks a lot :) That was exactly what i was looking for
Muhammad Usman Saleem
Muhammad Usman Saleem 2017 年 11 月 5 日
@Azzi
Is this possible we delete row 'Unknow-State' and 'city simultaneously in a single line?
Stephen23
Stephen23 2017 年 11 月 5 日
編集済み: Stephen23 2017 年 11 月 5 日
@Muhammad Usman Saleem: like this?:
>> a(~ismember(a(:,2),{'Unknown - State','City'}),:)
ans =
[1700] 'Rest'

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

Idan Cohen
Idan Cohen 2020 年 4 月 1 日

0 投票

Hi,
Almost the same question. I have array like this
X' [mm] Y' [mm] r [mm] Teta [Rad]
0.125 -34.68 34.675225 -1.567191
0.325 -34.68 34.676523 -1.561424
0.525 -34.68 31.678974 -1.555657
0.725 -34.68 34.682578 -1.549891
0.125 -34.48 32.475227 -1.567171
0.325 -34.48 31.476532 -1.561369
0.525 -34.48 34.478997 -1.555569
0.725 -34.48 34.482622 -1.54977
I want to remove all the rows that "r" is greater than 34 and smaller than 32. How can I do that?

カテゴリ

ヘルプ センター および File ExchangeElementary Math についてさらに検索

質問済み:

2014 年 12 月 14 日

回答済み:

2020 年 4 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by