How can i do loops (for cycles) with struct?
조회 수: 4 (최근 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!