How can i do loops (for cycles) with struct?
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi, I'm not so practical with Matlab but I need to do a for cycle with a matrix composed by struct (it is 1x91 cells, each one is a struct 1x1) because I loaded on Matlab 91 matrices 1000x512 and I joined them into a single struct.
I don't know how to do the cycle because occurs an error that says: Dot indexing is not supported for variables of this type.
The for cycle I've done is as usual, and so:
for i=1:numel(matrix_of_structs)
matrix_of_structs(i).vector=fft(matrix_of_structs(i).vector)
end
Maybe I'm so dumb.... But I can't reach this problem
Thank you in advance
0 Commenti
Risposta accettata
Stephen23
il 28 Giu 2019
Modificato: Stephen23
il 28 Giu 2019
"... a matrix composed by struct (it is 1x91 cells, each one is a struct 1x1) ..."
What you describe sounds like a 1x91 cell array of scalar structures, not a single structure array. So you will need to use cell array indexing to access each structure within the cell array, e.g.:
matrix_of_structs{i}
% ^ ^ access the content of the cell array
"...because I loaded on Matlab 91 matrices 1000x512 and I joined them into a single struct"
But what you described is a cell array of structures, not a single structure array. If the structures all have the same fields then you can easily convert your cell array into a structure array:
nonscalar_structure = [cell_array_of_scalar_struct{:}]
I recommend doing this, as then you can use very convenient syntaxes for accessing your data, including the syntax that you show in your question:
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Structures 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!