Extracting single numbers from each cell in a cell array
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Guglielmo Sonnino Sorisio
il 21 Mar 2022
Modificato: Voss
il 21 Mar 2022
I have a 451x1 cell array, each cell is a 57x41 double. From each cell (which represents a timepoint) I need to extract the value of one location, the same one for all cells. e.g. From all 451 cells I need to extract (32, 25) from the 57x41 double. I then need to combine these into a 451x1 double. How can I do this? I'm having trouble getting the correct notation.
Thank you
0 Commenti
Risposta accettata
Voss
il 21 Mar 2022
% first, create a cell array like yours:
C = cell(451,1);
for ii = 1:numel(C)
C{ii} = randn(57,41);
end
% look at the first couple of cells' (32,25) element:
C{1}(32,25)
C{2}(32,25)
% now get the specified element from each cell into a double array:
A = cellfun(@(x)x(32,25),C)
2 Commenti
Voss
il 21 Mar 2022
Modificato: Voss
il 21 Mar 2022
Anywhere my code uses C, your code should use u_filtered, but it's really just one line to do the actual indexing (the rest is to create my cell array, which you already have):
% get the specified element from each cell into a double array:
A = cellfun(@(x)x(32,25),u_filtered)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!