필터 지우기
필터 지우기

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 CenterFile Exchange에서 Structures에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by