フィルターのクリア

Extract fields from structure

10 ビュー (過去 30 日間)
Samy Alkhayat
Samy Alkhayat 2022 年 8 月 14 日
コメント済み: Dyuman Joshi 2022 年 8 月 15 日
Hello,
I have a structure A that includes 2 structures, B and C. I want to extract from structure "C" , to the workspace, specific fields that start with certain set of letter, i.e I want to extract fields that start wih XX_YY.
I did
S=[A.C(:)]; save('param.mat','-struct','S');
But the file takes forever to load to the workspace.
Thanks in Advance!
  3 件のコメント
Samy Alkhayat
Samy Alkhayat 2022 年 8 月 15 日
I actually not sure how to extract directly to workspace without saving to a variable and loading it.
Dyuman Joshi
Dyuman Joshi 2022 年 8 月 15 日
It is, as the answers below show

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

採用された回答

Stephen23
Stephen23 2022 年 8 月 15 日
A.C.XX_YY1 = 5;
A.C.XX_YY2 = 10;
A.C.ZZ = 3;
B = A.C;
F = fieldnames(B);
X = startsWith(F,'XX_YY');
B = rmfield(B,F(~X))
B = struct with fields:
XX_YY1: 5 XX_YY2: 10
  2 件のコメント
Samy Alkhayat
Samy Alkhayat 2022 年 8 月 15 日
編集済み: Samy Alkhayat 2022 年 8 月 15 日
Works! Thank you!
@Stephen23 any way to put the fields inside "B" into the workspace directly?

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

その他の回答 (1 件)

Matt J
Matt J 2022 年 8 月 14 日
編集済み: Matt J 2022 年 8 月 14 日
S.C.XX_YY1=5;
S.C.XX_YY2=10;
S.C.ZZ=3;
f=fieldnames(S.C);
I=startsWith(f,'XX_YY');
f=string(f(I));
for fI=string(f(I))'
Extraction.(fI)=S.C.(fI);
end
Extraction
Extraction = struct with fields:
XX_YY1: 5 XX_YY2: 10
  1 件のコメント
Samy Alkhayat
Samy Alkhayat 2022 年 8 月 15 日
@Matt J it works except I get the error below:
The logical indices contain a true value outside of the array bounds.
Any advice?
Thanks in advance!

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

カテゴリ

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

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by