accessing data from a struct

255 ビュー (過去 30 日間)
cgo
cgo 2018 年 7 月 21 日
回答済み: Anas Alakhras 2023 年 2 月 28 日
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 件のコメント
madhan ravi
madhan ravi 2018 年 7 月 21 日
Could you upload the code?
Stephen23
Stephen23 2018 年 7 月 21 日
How to access data in structures is explained in the MATLAB documentation:

サインインしてコメントする。

採用された回答

Stephan
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 件のコメント
Samuel Suakye
Samuel Suakye 2022 年 12 月 13 日
How then do you open a .mat file which is a struct?
Stephen23
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 件)

Anas Alakhras
Anas Alakhras 2023 年 2 月 28 日
R.X

カテゴリ

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