Changing multiple structure vales
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a problem where I have a structure D where D.r = 33.75e-3;D.L = 143e-3;D.d=103e-3;D.m2=.5355;D.L1=45.9e-3;D.m3=.5110;D.Im2=1.59e-3;D.ncyl=2;D.m1=0;D.r1=0;D.Im1=0;. I want to create a new strucure D1 so that D1 = D except for D1.r,D1.L,D1.d, and D1.m2 are changed. So that, D1.r = D.r + (D.r.*10e-6), D1.L = D.L + (D.L.*10e-6), D1.d = D.d + (D.d.*10e-6), D1.m2 = D.m2 + (D.m2.*10e-6). Is there a way to do this using a for loop or do I have to change each one individually?
댓글 수: 1
Walter Roberson
2012년 11월 4일
Your question is difficult to read. Consider adding line breaks and markup.
답변 (1개)
Akiva Gordon
2012년 11월 4일
% Setup structure "S"
S.a = 11;
S.b = 22;
S.c = 33;
S.d = 44;
% This is the list of fields in "S" that I want to change
fields = {'c', 'd'};
for i = 1:numel(fields)
% Use dynamic field references to set these fields
S.(fields{i}) = S.(fields{i})*(1+1e-5);
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!