How can i do loops (for cycles) with struct?
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!