I have a large cell array (a part of it I attached). This cell array contains other cells. My problem occurs at rows with contents similar to sequence{28,1} where I have zeros or numbers close to zero in the second column. How can I delete all rows which contain a number less than 0.001 in the second column. The numbers in the second column are cells themselves and the letters in the first columns are cells of characters.

 Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 16 Jul. 2015
Bearbeitet: Azzi Abdelmalek am 16 Jul. 2015
A=A(A(:,2)>=0.001)

4 Kommentare

Eli Dim
Eli Dim am 16 Jul. 2015
Bearbeitet: Eli Dim am 16 Jul. 2015
this does not work, i think it is because the numbers of the second column are cells themselves and not doubles. I tried to do something like this:
for i = 1:size(dispatch_seq,1)
curCell_dispatch = dispatch_seq{i};
curCell_disp_seq_power = cell2mat(vertcat(curCell_dispatch_seq(:,2)));
indices1 = find(curCell_dispatch_seq_power(:,1)<=0.01);
curCell_dispatch_seq_power(indices1,:) = [];
dispatch_seq(i) = {curCell_dispatch_seq_power};
In this way I get rid of the rows I don't want but I have no idea how to append the corresponding first column to this ...
out=cellfun(@(x) x([x{:,2}]>=0.001,:),dispatch_seq ,'un',0)
Eli Dim
Eli Dim am 16 Jul. 2015
Thank you, this works perfectly, but can you explain to me what the syntax means?
Cellfun allows you to apply any function you want to each cell. It's like a for loop, where x represent each cell at each increment. Read the Documentation

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by