Very weird Dot indexing is not supported for variables of this type
7 次查看(过去 30 天)
显示 更早的评论
I just built my first Matlab class definition, designed to participate in my .mlapp program.
Here's an excerpt of my .mlapp file:
properties (Access = public)
UIAxes3 % another detail plot
Detail1
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
xlabel(app.UIAxes, '')
ylabel(app.UIAxes, '')
xlabel(app.UIAxes2, '')
ylabel(app.UIAxes2, '')
app.UIAxes2.XLim = [0 .3];
x = linspace(-1,1,200);
y = cos(x * app.FrequencyEditField.Value);
x
y
app.UIAxes3 = uiaxes(app.UIFigure);
title(app.UIAxes3, 'Extra')
app.UIAxes3.Position = [462 31 147 129];
app.UIAxes3.XLim = [.3 .6];
plot(app.UIAxes,x,y)
plot(app.UIAxes2,x,y)
plot(app.UIAxes3,x,y)
app.Detail1 = DetailGroup(app, 300, 500)
end
. . .
end
Here's the error it gave me.
Error using DetailGroup
Dot indexing is not supported for variables of this type.
Error in TryApp/startupFcn (line 52)
app.Detail1 = DetailGroup(app, 300, 500)
Makes no sense! In the line above, "plot(app.UIAxes3,x,y)", it is perfectly clear that app is the sort of thing that works with dot indexing notation. (all was working until I added the troublesome line.) Is this some misdirected message really meaning to tell me that "DetailGroup is undefined"?
Here's DetailGroup.m, and it's in the same directory with the main mlapp file.
classdef DetailGroup
properties
app
x
y
Graph
Peak1Label
Peak1
Width1Label
Width1
Peak2Label
Peak2
Width2Label
Width2
TOFLabel
TOF
end
methods
function obj = DetailGroup(this, app, x, y)
% Create Graph
app.Graph = uiaxes(app.UIFigure);
title(app.Graph, 'Detail')
zlabel(app.Graph, 'Z')
app.Graph.Position = [x y 147 144];
% app.Graph.Position = [396 222 147 144];
% Create Peak1Label
this.Peak1Label = uilabel(this.UIFigure);
this.Peak1Label.HorizontalAlignment = 'right';
this.Peak1Label.Position = [x+168 y+111 42 19];
this.Peak1Label.Text = 'Peak 1';
% Create Peak1
this.Peak1 = ui(this.UIFigure, 'numeric');
this.Peak1.Position = [x+225 y+109 54 23];
% Create Width1Label
this.Width1Label = uilabel(this.UIFigure);
this.Width1Label.HorizontalAlignment = 'right';
this.Width1Label.Position = [x+168 y+160 46 22];
this.Width1Label.Text = 'Width 1';
% Create Width1
this.Width1 = ui(this.UIFigure, 'numeric');
this.Width1.Position = [x+225 y+197 54 23];
% Create Peak2Label
this.Peak2Label = uilabel(this.UIFigure);
this.Peak2Label.HorizontalAlignment = 'right';
this.Peak2Label.Position = [x + 168 y+173 42 22];
this.Peak2Label.Text = 'Peak 2';
% Create Peak2
this.Peak2 = ui(this.UIFigure, 'numeric');
this.Peak2.Position = [x+225 y+174 54 23];
% Create Width2Label
this.Width2Label = uilabel(this.UIFigure);
this.Width2Label.HorizontalAlignment = 'right';
this.Width2Label.Position = [x+168 y+150 46 22];
this.Width2Label.Text = 'Width 2';
% Create Width2
this.Width2 = ui(this.UIFigure, 'numeric');
this.Width2.Position = [x+225 y+151 54 23];
% Create TOFLabel
this.TOFLabel = uilabel(this.UIFigure);
this.TOFLabel.HorizontalAlignment = 'right';
this.TOFLabel.Position = [x+182 y+127 28 22];
this.TOFLabel.Text = 'TOF';
% Create TOF
this.TOF = ui(this.UIFigure, 'numeric');
this.TOF.Position = [x+225 y+128 54 23];
end
end
end
0 个评论
回答(1 个)
Matt J
2024-1-8
编辑:Matt J
2024-1-8
You have only passed 3 arguments to DetailGroup when it expects 4. Therefore, it is trying to do operations in which the double value 300 is used to perform dot indexing. Likely, the function signature for DetailGroup should be,
function DetailGroup(this, x, y)
2 个评论
Matt J
2024-1-8
编辑:Matt J
2024-1-8
Thanks. I misunderstood constructor syntax. Got it.
You're welcome. Please Accept-click the answer to indicate that your question is resolved.
Except: I would have expected the error to originate within the DetailGroup constructor, not in the call to it. Right??
Both would appear in the error message normally.
另请参阅
类别
在 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!