assigning value to a changing struct field
Ältere Kommentare anzeigen
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 Kommentar
Stephen23
am 9 Dez. 2018
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.
Antworten (2)
madhan ravi
am 5 Dez. 2018
Bearbeitet: madhan ravi
am 5 Dez. 2018
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 Kommentar
nadav silberman
am 9 Dez. 2018
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:
Kategorien
Mehr zu Structures finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!