Very weird Dot indexing is not supported for variables of this type

조회 수: 6 (최근 30일)
Ken
Ken 2024년 1월 8일
편집: Matt J 2024년 1월 8일
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

답변 (1개)

Matt J
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
Ken
Ken 2024년 1월 8일
Thanks. I misunderstood constructor syntax. Got it.
Except: I would have expected the error to originate within the DetailGroup constructor, not in the call to it. Right??
Matt J
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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by