Hello, I'd like to asiign a value to a struct with changing fields, but get a 'dimension mismatch' error. my code is as follows:
gear_ytpe=['P' 'G'];
axis=['x' 'y' 'z']
for ii=1:2
for jj=1:3
statistics.Envelop.CF.gear_ytpe(ii).Diff.axis(jj)=1:1:1000
end
end
Thnks in advance,
Nadav

댓글 수: 1

Stephen23
Stephen23 2018년 12월 9일
Note that in MATLAB the square brackets [] are a concatenation operator, so this:
axis = ['x' 'y' 'z']
is exactly equivalent to this:
axis = 'xyz'
MATLAB does not have a "list" operator.

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

답변 (2개)

madhan ravi
madhan ravi 2018년 12월 5일
편집: madhan ravi 2018년 12월 5일

0 개 추천

gear_ytpe={'P', 'G'};
axis={'x' ,'y' ,'z'};
for ii=1:2
for jj=1:3
statistics.Envelop.CF.gear_ytpe{ii}.Diff.axis{jj}=1:1:1000;
end
end

댓글 수: 1

thank you for your answer, but that doesn't solve my problem.
If you'll look in the struct after it is being created you'll notice the field "statistics.Envelop.CF.gear_ytpe". I don't want the field gear_ytpe. instead I want two fields - "P" and "G", which are the cells inside gear_ytpe variable

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

Stephen23
Stephen23 2018년 12월 9일
편집: Stephen23 2018년 12월 9일

0 개 추천

ytpe = {'P','G'}; % more robust as cell array.
axis = {'x','y','z'}; % more robust as cell array.
for ii = 1:numel(ytpe)
fi = ytpe{ii};
for jj = 1:numel(axis)
fj = axis{jj};
statistics.Envelop.CF.gear_ytpe.(fi).Diff.axis.(fj) = 1:1:1000
end
end
See:

카테고리

도움말 센터File Exchange에서 Structures에 대해 자세히 알아보기

태그

질문:

2018년 12월 5일

편집:

2018년 12월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by