# Extract contents of cell array based on rows

2 vues (au cours des 30 derniers jours)
Emily le 2 Mai 2023
Modifié(e) : Paul le 2 Mai 2023
I have a 3 x 1 cell array (A), where each cell contains a 30 x 8 double. I want to extract certain rows of each 30 x 8 double based on the values in the 3rd column (ranges from 1-6)
Here is the first 12 lines of A{1,1}
30 6 1 -7.37500000000000 -46.6850000000000 16476 0.188000000000000 0.906000000000000
31 6 2 -7.25100000000000 -45.6730000000000 16450 0.250000000000000 0.764000000000000
32 6 3 -7.28200000000000 -45.3310000000000 16455 0.271000000000000 1.09300000000000
33 6 4 -7.24300000000000 -45.2850000000000 16434 0.235000000000000 0.932000000000000
34 6 5 -7.28900000000000 -45.1140000000000 16435 0.195000000000000 0.756000000000000
35 6 6 -7.24900000000000 -45.0640000000000 16448 0.310000000000000 0.831000000000000
168 6 1 -7.34000000000000 -45.9470000000000 16374 0.247000000000000 1.02800000000000
169 6 2 -7.28000000000000 -44.9610000000000 16333 0.258000000000000 1.14600000000000
170 6 3 -7.30600000000000 -44.4130000000000 16369 0.246000000000000 0.955000000000000
171 6 4 -7.26600000000000 -44.2830000000000 16364 0.239000000000000 1.12400000000000
172 6 5 -7.23400000000000 -44.2240000000000 16359 0.265000000000000 1.00300000000000
173 6 6 -7.26000000000000 -44.3960000000000 16367 0.257000000000000 0.921000000000000
306 6 1 -7.40500000000000 -45.6630000000000 16352 0.235000000000000 0.960000000000000
For each of the three 30 x 8 doubles contained in cell array A, I want to extract all of the rows where column 3 is greater than 3.
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

Paul le 2 Mai 2023
Without having example data to try ....
result = cellfun(@(A) A(:,3)>3,A,'UniformOutput',false);
##### 3 commentairesAfficher 1 commentaire plus ancienMasquer 1 commentaire plus ancien
Paul le 2 Mai 2023
Modifié(e) : Paul le 2 Mai 2023
My mistake. Should be
result = cellfun(@(A) A(A(:,3)>3,:),A,'UniformOutput',false);
Should return a 3x1 cell with the arrays you want.
Emily le 2 Mai 2023
This worked, thank you!!

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by