필터 지우기
필터 지우기

How remove a field inside a structure?

조회 수: 20 (최근 30일)
Neda
Neda 2018년 7월 25일
답변: Guillaume 2018년 7월 25일
I need to remove a field which is inside a structure. I did attach the file to help for understanding the issue.
sd does have a field called Variables, and inside Variables filed, there are 6 fields. then inside each of these, there is Attributes and Text. I need to remove Text from all. I tried the following, but the error is saying too many arguments.
fieldsS = fieldnames(sd.Variables);S = rmfield(sd,fieldsS(:),'Text');code
I read this link, but this case is different as there are many fields inside the structure. https://uk.mathworks.com/matlabcentral/answers/29610-how-do-i-delete-a-field-variable-from-a-structure%20

채택된 답변

Giridharan Kumaravelu
Giridharan Kumaravelu 2018년 7월 25일
fieldsS = fieldnames(sd.Variables);
for i = 1:length(fieldsS)
S.Variables.(fieldsS{i}) = rmfield(sd.Variables.(fieldsS{i}),'Text');
end
This could help.
  댓글 수: 1
Neda
Neda 2018년 7월 25일
Thank you so much. very helpful

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Guillaume
Guillaume 2018년 7월 25일
I haven't downloaded your mat file to check but this will probably do what you want:
sd.Variables = structfun(@(var) rmfield(var, 'Text'), sd.Variables, 'UniformOutput', false);
This assumes that the Variables field is indeed scalar.

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by