How to extract data from all matrixes of a cell array?
Mostra commenti meno recenti
I have a cell array 1x23 and every matrix contains 1x921600 and they're all same size but i only need to extract data from all the matrixes from array 1 until 456000 and again from 456000 until 764500. how can i do that ?
Risposta accettata
Più risposte (1)
Reeshabh Kumar Ranjan
il 30 Giu 2020
By extracting data, I assume you mean accessing the elements. This seems more of a syntax question.
Let's say you have a cell array
ca = {[1 2 3], [4 5 6], [7, 8, 9]}
Now, you can just loop over it
for i = 1 : length(ca)
matrix = ca{i}
% you have the matrix in each iteration now, access its elements any way you like
end
5 Commenti
Yasyas9
il 30 Giu 2020
Evangelia Tripoliti
il 14 Set 2022
@Reeshabh Kumar Ranjan this is not correct, as variable matrix will only save the last cell matrix, i.e. [7,8,9]; Variable matrix should change name within the loop for each iteration to extract all 3 cell matrices
"Variable matrix should change name within the loop for each iteration to extract all 3 cell matrices"
Changing variable names dynamically should be avoided:
Rather than doing that, a much better solution is to use indexing... which means that we don't need to do anything at all, because the input cell array ca can already be easily accessed using indexing.
Nice avatar picture, by the way.
Evangelia Tripoliti
il 14 Set 2022
This is partly true. What if you have 100 matrices in a cell array? will you name the individually?
"This is partly true."
Exactly which part is untrue?
"What if you have 100 matrices in a cell array?"
As stated in my previous comment, I would use simple and efficient indexing into the cell array. This is not just a hypothetical situation, I do this very often (e.g. processing TB of data in thousands of files).
"will you name the individually?"
No.
Categorie
Scopri di più su Matrix Indexing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!