Appdesigner - slider changed function - missing argument

Hello, I am trying to programmatically change the scaling of an imgae on a uifigure by using a slider
fig = uifigure('Name','Montage');
fig.Position = [300 500 1200 400];
g = uigridlayout(fig);
g.RowHeight = {'2x','2x','1x'};
g.ColumnWidth = {'1x'};
ax1 = uiaxes(g);
ax1.Layout.Row = [1 2];
ax1.Layout.Column = 1;
sld1=uislider(g,'ValueChanged',@(sld1,event) updateImage(event,ax1,sld1)); %Need to palso pass ax1 I think
sld1.Layout.Row = [3];
sld1.Layout.Column = 1;
mx=double(max(Image2(:)));
sld1.Limits = [1 mx];
v=min(mx,round(hi));
sld1.Value=double(v)
imshow(Image2,[lo hi],'Parent',ax1);
Where
function results = updateImage(event,ax1,sld1)
value=sld1.Value
ax1.CLim=[0 max(1,value)];
But this leads to the error:
Check for missing argument or incorrect argument data type in call to function 'updateImage'.
Error in PhotonControl>@(sld1,event)updateImage(event,ax1,sld1) (line 2398)
sld1=uislider(g,'ValueChanged',@(sld1,event) updateImage(event,ax1,sld1));
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 429)
Error while evaluating Slider PrivateValueChangedFcn.

 Accepted Answer

Hello,
Right click on the Slider component, create a callback - ValueChangedFcn
% Example text, adjust to the actual component names
% Value changed function: CupHeightWeightEditField
function SliderValueChanged(app, event)
value = app.SliderComponent.Value
app.UIAxes.CLim=[0 value];
end

9 Comments

Hello, but this isn't my main UIfigure, its called from a pushbutton on my UIfigure which I want to create a figure (uifigure2) showing an image and have the imshow limits changed by the slider.
I have never tried this, but if your UI creates another uifigure, then you probably need to save a handle to it
app.UIFig2 = uifigure() % create UIFig2 as a property so you can have access to it wherever
% Value changed function: SliderValueChanged
function SliderValueChanged(app, event)
value = app.SliderComponent.Value
app.UIFig2.UIAxes.CLim=[0 value]; % Change UIAxes to the name of your uiaxes handle in the other uifigure
end
hmm, it doesn't seem to be doing anything.
my slider is called sld1
sld1=uislider(g);
So I have created a public function:
function sld1ValueChanged(app, event)
value = app.sld1.Value
app.UIFig2.ax1.CLim=[0 value]; %
end
everythime I change the slider, there is no "value" reported in the command window, so it appears this function isn't being called.
I can create a demo app later today, on the phone now. This doesn't work because you created slider whose parent is groot(default option, since you haven't supplied parent to it), it has no connection with your app.
As before,
app.UIFig2 = uifigure()
App.Slider = uislider() % set parent property to it app.UIFig2
app.Ax2 = uiaxes() % set parent as well.
Sorry for the previous comment, as it wasn't clear enough.
Thankyou for any further help (and all the help so far given!)
Jason
Hello,
In the demo there's an example controlling the uiaxes with sliders, just with another parameter - XLim.
I haven't understood where is the slider located, on the main or on the newly created figure, so both ways are included.
Thankyou, will take a look. (The slider is on the newly created figure)
Just wanted to share this here, since this is a proper information to learn from regarding your issue. https://www.mathworks.com/help/matlab/creating_guis/creating-multiwindow-apps-in-app-designer.html
Thankyou, this is what I was missing:
app.Slider2.ValueChangedFcn = createCallbackFcn(app, @SliderValueCback, true); % Creating callback, see function

Sign in to comment.

More Answers (0)

Categories

Find more on Environment and Settings in Help Center and File Exchange

Asked:

on 17 Nov 2020

Commented:

on 18 Nov 2020

Community Treasure Hunt

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

Start Hunting!