Error “dot indexing...comma-separated list with 2 values” doesn’t seem applicable
18 views (last 30 days)
Show older comments
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:
In the debugger I can see that peak1 is an object of type Peak, and here is its value:
So which part of this could be causing the problem?
2 Comments
Stephen23
on 7 Feb 2024
"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
Accepted Answer
More Answers (1)
Cris LaPierre
on 6 Feb 2024
Moved: Cris LaPierre
on 6 Feb 2024
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 Comment
Stephen23
on 7 Feb 2024
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
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!