identifying the elements of a cell
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
CLARK KENDRICK GO
le 10 Juil 2018
Commenté : Sammit Jain
le 10 Juil 2018
I have a 700x8 cell, with each cell having a matrix 6x2 in size. I want to get the first row of each cell. How do I perform this?
0 commentaires
Réponse acceptée
Mandeep Singh
le 10 Juil 2018
Modifié(e) : Mandeep Singh
le 10 Juil 2018
From my understanding of the question, you can achieve the required task by following snippet of code:
cnt = 1;
for i = 1:700
for j = 1:8
a(cnt) = C{i,j}(1,:); % stores the first row of each cell in a;
cnt = cnt + 1;
end
end
1 commentaire
Sammit Jain
le 10 Juil 2018
I think using a for loop will be slightly computationally expensive in this case.
Plus de réponses (1)
Sammit Jain
le 10 Juil 2018
Hi, This seems to be a simple case of cell indexing.
Let's call your original cell array (of cells) 'mainCellArray'
Now, let's have allRowsArray = [mainCellArray{:}] Then, firstRowArray = [allRowsArray{1,:}]
Essentially, we're first re-arranging the contents of the main cell array, stacking them one next to the other, then we just index the first row.
Here's what the code should look like:
allRowsArray = [mainCellArray{:}];
firstRowArray = [allRowsArray{1,:}]
Hope this helps. If in case you want to pick a different combination of rows/columns, then just try to transpose these concatenations and see if you get what you want.
Cheers.
0 commentaires
Voir également
Catégories
En savoir plus sur Matrix Indexing 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!