remove rows with certain element in cell arrays

4 ビュー (過去 30 日間)
FATEMEH
FATEMEH 2012 年 2 月 2 日
In the following data set, I want to keep only the rows with 'Hourly' element, thus only row 2. I use the following, but it doesn't work. Can anybody help me?
data={'s' 'e' 'daily'; 't' 'c' 'hourly'; 'm' 'b' 'daily'}
data_2 = cellfun(@(x) x(x(:,3)=='Hourly'), data, 'UniformOutput', false)

採用された回答

Geoff
Geoff 2012 年 2 月 2 日
Did you mean to write:
x{:,3}=='Hourly'
The curly-braces thing trips me up all the time =)
  2 件のコメント
Geoff
Geoff 2012 年 2 月 2 日
Err... Sorry, this works:
data_2 = data(find(strcmp(data(:,3), 'hourly')),:)
-g-
FATEMEH
FATEMEH 2012 年 2 月 2 日
thanks a lot!

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

その他の回答 (1 件)

Jan
Jan 2012 年 2 月 2 日
data = {'s' 'e' 'daily'; ...
't' 'c' 'hourly'; ...
'm' 'b' 'daily'};
data2 = data(strcmpi(data(:, 3), 'hourly'), :);
  1 件のコメント
FATEMEH
FATEMEH 2012 年 2 月 2 日
thanks a lot!

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

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by