How to extract element of all matrices within a cell array using cellfun?
Afficher commentaires plus anciens
I need to extract (2,1) i.e. second row and first column element of all matrices within cell array ?
Réponse acceptée
Plus de réponses (2)
Jos (10584)
le 6 Déc 2018
This looks like homework to me. Here is a big hint:
Create a function that extracts this for you and use cellfun to apply it to all cells ...
MyFun = @(M) M(...)
5 commentaires
NS
le 6 Déc 2018
James Tursa
le 6 Déc 2018
The error indicates that some of your matrices do not have a (2,1) element. So you will need to deal with that. Is this not expected? I.e., are all of your matrices supposed to have a (2,1) element? If not, then what do you want for a result?
NS
le 6 Déc 2018
James Tursa
le 6 Déc 2018
Modifié(e) : James Tursa
le 6 Déc 2018
The value of the (2,1) element makes no differrence to indexing ... whether it is finite or inf or NaN. You will not get an "index exceeds" error just because the element is NaN. You get the error because there is no (2,1) element. You need to re-check your matrices. What do you get when you run this:
C = your cell array of matrices
min(cellfun(@numel,C))
min(cellfun(@(c)size(c,1),C))
NS
le 7 Déc 2018
Ali Nik
le 16 Avr 2023
0 votes
Hi I want to use all nested arrays inside each cell. Thank you for your help His photo is attached.
1 commentaire
Image Analyst
le 16 Avr 2023
Not sure how this is an answer to @NS. And when you said "His photo is attached", we're not sure what photo you're talking about or where it is. Certainly NS's photo is not attached to your Answer.
If you have your own question, start a new question and attach your cell array in a .mat file after you read this:
Catégories
En savoir plus sur Matrices and Arrays dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!