Expected one output from a curly brace or dot indexing expression, but there were 2 results.

조회 수: 60 (최근 30일)
Hi.I working with a code to manipulate some data and here are the lines which gives error
S12(m).x2(n)=S2(tn4).x(ts4) % line 104
S12(m).dx2(n)=S2(tn4).dx(ts4) % line 105
S12(m).z(n)=S2(tn4).y(ts4) % line 106
The error is,
Expected one output from a curly brace or dot indexing expression, but there were 2 results.
Error in data_man (line 104) S12(m).x2(n)=S2(tn4).x(ts4)
How can I fix this error?
  댓글 수: 3
SS
SS 2019년 8월 13일
편집: SS 2019년 8월 13일
Here is the data file, I renamed the Newtracks as S2 in the following code. The error is in line 104
S12(m).x2(n)=S2(tn4).x(ts4) % line 104
S12(m).dx2(n)=S2(tn4).dx(ts4) % line 105
S12(m).z(n)=S2(tn4).y(ts4) % line 106

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

채택된 답변

Bruno Luong
Bruno Luong 2019년 8월 13일
편집: Bruno Luong 2019년 8월 13일
In general you are not allow to assign multi-level structures with non-scalar indexing in one shot, you need to do in 2 steps.
% S12(m).x2(n)=S2(tn4).x(ts4)
x2 = {S12(m).x2};
x = {S2(tn4).x};
for k=1:length(x2)
x2{k}(n) = x{k}(ts4);
end
[S12(m).x2] = deal(x2{:});
  댓글 수: 3
Chuck Olosky
Chuck Olosky 2020년 8월 2일
This approach worked for:
names = {'a' 'b' 'c'};
dStruct = repmat(struct('name',''),size(names));
[dStruct.name] = deal(names{:});
Also works without "deal":
[dStruct.name] = names{:};
In other threads, there are discussions regarding "deal" being unnecessary in later releases.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by