Error “dot indexing...comma-separated list with 2 values” doesn’t seem applicable
조회 수: 15 (최근 30일)
이전 댓글 표시
I am getting this very mysterious error message.
Intermediate dot '.' indexing produced a comma-separated list with 2 values, but it must produce a single value when followed by subsequent indexing operations.
It comes from the marked line in the code below.
methods (Access = public)
function Display(comp, peak1, peak2)
% peak1, peak2 are class Peak objects; data are the relevant Y values
% Use this function to update the underlying components
comp.Peak1EditField.Value =peak1.ActualAmplitude; % <<<----------- ERROR
comp.Width1EditField.Value= peak1.HWInterval;
if peak1.IsPair
comp.Peak2EditField.Value = peak2.ActualAmplitude;
comp.Width2EditField.Value= peak2.HWInterval;
comp.TOFEditField.Value = peak1.TOF;
end
end
end
I have read up and understand what this message is about, but I don't understand how it could be applicable here. We are in code for a custom component, whose structure is this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1609596/image.png)
In the debugger I can see that peak1 is an object of type Peak, and here is its value:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1609601/image.png)
So which part of this could be causing the problem?
댓글 수: 2
Stephen23
2024년 2월 7일
"So which part of this could be causing the problem?"
Note how X is non-scalar:
X(1).Y.Z = 1;
X(2).Y.Z = 2;
X.Y.Z
채택된 답변
추가 답변 (1개)
Cris LaPierre
2024년 2월 6일
이동: Cris LaPierre
2024년 2월 6일
I suspect peak is no longer 1x1 when the error occurs. Can you confirm?
The fix might be to ensure only a single value is returned
comp.Peak1EditField.Value =peak1(1).ActualAmplitude;
댓글 수: 1
Stephen23
2024년 2월 7일
In that case only the first RHS comma-separated list element is returned without error:
S = struct('A',{1,2})
X = S.A % no error, 1st value is assigned, all others are discarded
More generally, a comma-separated list on the LHS will accept <=N of the N elements from the RHS comma-separated list:
C = cell(1,3);
D = {1,2,3,pi,sqrt(2)}
[C{:}] = D{:} % no error
Of course trying to obtain >N items will throw an error:
C = cell(1,6);
[C{:}] = D{:} % fails
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!