Error “dot indexing...comma-separated list with 2 values” doesn’t seem applicable
18 次查看(过去 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:
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?
采纳的回答
更多回答(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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!