フィルターのクリア

How can i do loops (for cycles) with struct?

4 ビュー (過去 30 日間)
wolss
wolss 2019 年 6 月 28 日
編集済み: Stephen23 2019 年 6 月 28 日
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

採用された回答

Stephen23
Stephen23 2019 年 6 月 28 日
編集済み: Stephen23 2019 年 6 月 28 日
"... 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 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by