Error “dot indexing..​.comma-sep​arated list with 2 values” doesn’t seem applicable

18 views (last 30 days)
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
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
Intermediate dot '.' indexing produced a comma-separated list with 2 values, but it must produce a single value when followed by subsequent indexing operations.
Stephen23
Stephen23 on 7 Feb 2024
Edited: Stephen23 on 7 Feb 2024
Of course any type of trailing indexing will throw this error (not just dot-indexing):
X(1).Y = 1;
X(2).Y = 2;
X.Y(:)
Intermediate dot '.' indexing produced a comma-separated list with 2 values, but it must produce a single value when followed by subsequent indexing operations.

Sign in to comment.

Accepted Answer

Kenneth
Kenneth on 7 Feb 2024
The real answer, when it came, was far stranger. What actually happened is that at the calling level I had called it with
app.PeakDetail.Display(peak1, peak2)
but I had made a change so that app.PeakDetail was now in fact an ARRAY of PeakDetail custom component instances. To my utter astonishment, Matlab allowed me to make this method call based on an array of the object, rather than a single instance. I know other programming language that would allow this!
So inside the Display function, comp.Peak1EditField.Value referred to multiple edit fields, and an assignment to multiple edit fields at one shot is not supported. Sad to say, the debugger would not show me teh value of comp.Peak1EditField, so it took far too long to analyze the problem.
Wow. That was a doozy!

More Answers (1)

Cris LaPierre
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
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})
S = 1×2 struct array with fields:
A
X = S.A % no error, 1st value is assigned, all others are discarded
X = 1
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)}
D = 1×5 cell array
{[1]} {[2]} {[3]} {[3.1416]} {[1.4142]}
[C{:}] = D{:} % no error
C = 1×3 cell array
{[1]} {[2]} {[3]}
Of course trying to obtain >N items will throw an error:
C = cell(1,6);
[C{:}] = D{:} % fails
Insufficient number of outputs from right hand side of equal sign to satisfy assignment.

Sign in to comment.

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!