remove rows with certain element in cell arrays

1 Ansicht (letzte 30 Tage)
FATEMEH
FATEMEH am 2 Feb. 2012
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)

Akzeptierte Antwort

Geoff
Geoff am 2 Feb. 2012
Did you mean to write:
x{:,3}=='Hourly'
The curly-braces thing trips me up all the time =)
  2 Kommentare
Geoff
Geoff am 2 Feb. 2012
Err... Sorry, this works:
data_2 = data(find(strcmp(data(:,3), 'hourly')),:)
-g-
FATEMEH
FATEMEH am 2 Feb. 2012
thanks a lot!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Jan
Jan am 2 Feb. 2012
data = {'s' 'e' 'daily'; ...
't' 'c' 'hourly'; ...
'm' 'b' 'daily'};
data2 = data(strcmpi(data(:, 3), 'hourly'), :);

Kategorien

Mehr zu Cell Arrays finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by