Error Using uislider. 'slider' is not a valid STYLE for uislider.
2 次查看(过去 30 天)
显示 更早的评论
I am making an app with MATLAB App Designer with lines that have dots at one of their end points.
There are two rotation methods for the points, one with an edit field and one with a slider.
When an end point of a node is clicked, it launches a figure with the slider on it to rotate the line along the dot. This works when you first use it. But after the second time of changing the value with slider (or third, multiple times basically) it breaks and gives the following error.
"error using uislider
'slider' is not a valid STYLE for uislider. STYLE must be 'slider' or 'range'."
The error message is very unclear, another person also had this issue with a 'range' slider but since I am not inputting an array, it shouldn't have been an issue? When this error is given the figure still pops up but it doesn't have the slider in it.
Here is the part of code that creates the slider in the grid of the figure.
sld = uislider(grid, "slider", "Value", app.AngledegEditField.Value);
sld.ValueChangingFcn = @(src,event) angleChanger(src, event, app);
sld.Layout.Row = [1 2];
sld.Layout.Column = [1 5];
sld.Limits = [-360 360];
sld.MajorTicks = [-360 -270 -180 -90 0 90 180 270 360];
sld.MajorTickLabels = sld.MajorTicks + "°";
sld.MinorTicks = [-315 -225 -135 -45 45 135 225 315];
Here is the part of the code that matches the changing value with the Edit Field, the change is made from going to the Edit Field from Value, then applying in the plot.
function angleChanger(src, event, app)
val = event.Value;
app.AngledegEditField.Value = val;
Apply(app); %In this function the change is applied from Edit Field.
end
And here is the part of the code that applies the change in the Edit Field to the node in the plot.
selectedPoint.NodeData.angle = angle; %This is inside the Apply(app) function.
Thank you.
1 个评论
Matlab Pro
2024-7-2
Hi @Ozan
The best is - if you could create s simplified ML app file (and attach it, of course).. with relevant code
Otherwise -it is hard to re-create your specific scenario
采纳的回答
更多回答(2 个)
Matlab Pro
2024-7-2
"This works when you first use it. But after the second time "..
So 1st time you create the figure+slider - and everything is OK
Other calls - you should not create a new figure, rather then just find the existing handle of uifigure/uislider and use them..
Do you do this???
(You can use my File Xchange submission "getapp" for this https://www.mathworks.com/matlabcentral/fileexchange/168921-getapp?s_tid=srchtitle)
Here is a small example that can give an idea..
function main_slider_issue()
hfig = uifigure(Name=mfilename);
ax = uiaxes(Parent=hfig);
x = 1:10;
hLine = line(x,x.^2,'Parent',ax);
hLine.Marker = 'o';
hLine.ButtonDownFcn = @(h,e)hLine_ButtonDownFcn(h,e);
%-----------------------------------------------------------
function hLine_ButtonDownFcn(hObject, eventData)
appName = 'figure_with_Slider';
hFig = getapp(appName); % Look for existing uifigure withe the relevant name
if isempty(hFig) % Create figure
hFig = uifigure(Name=appName);
hSlider = uislider('Parent',hFig);
hEdit = uieditfield('Parent',hFig);
hEdit.Position = [100,200,100,22];
else % "find" the relevant controls' handles
hEdit = findall(hFig,'Type','uieditfield');
hSlider = findall(hFig,'Type','uislider');
end
%% Continue code...
0 个评论
Walter Roberson
2024-7-2
uislider() does not take a positional parameter named slider
uislider() accepts the name/value pair 'style', 'slider'
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!