Error Using uislider. 'slider' is not a valid STYLE for uislider.
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commento
Matlab Pro
il 2 Lug 2024
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
Risposta accettata
Più risposte (2)
Matlab Pro
il 2 Lug 2024
"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 Commenti
Walter Roberson
il 2 Lug 2024
uislider() does not take a positional parameter named slider
uislider() accepts the name/value pair 'style', 'slider'
0 Commenti
Vedere anche
Categorie
Scopri di più su Introduction to Installation and Licensing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!