accessing data from a struct
조회 수: 251 (최근 30일)
이전 댓글 표시
I have R, which is a 1x1 struct, which contains a matrix named X. I want to access X, how do I this? I want to load X into the workgroup.
R(1) doesn't seem to do it.
댓글 수: 2
Stephen23
2018년 7월 21일
How to access data in structures is explained in the MATLAB documentation:
채택된 답변
Stephan
2018년 7월 21일
편집: Stephan
2018년 7월 21일
Hi,
A = R.X
assigns the Matrix saved in the field X of the struct R to A.
% define empty struct
R = struct()
% add field X containing a matrix
R.X = [1 2 3; 4 5 6]
% assign the matrix from field X to new variable A
A = R.X
% get one element from field x and assign to a
a = R.X(2,3)
Best regards
Stephan
댓글 수: 2
Stephen23
2022년 12월 13일
편집: Stephen23
2022년 12월 13일
"How then do you open a .mat file which is a struct?"
A MAT-file is not a structure, a MAT-file is a container which can hold many variables of many classes. It is certainly possible that one or more of those variables are structures (but that does not mean that the file itself "is" a structure).
MAT-files are never/rarely opened, they are simply LOADed:
S = load(nameofthematfile)
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!