Appdesigner - slider changed function - missing argument

조회 수: 9 (최근 30일)
Jason
Jason 2020년 11월 17일
댓글: Jason 2020년 11월 18일
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.

채택된 답변

Mario Malic
Mario Malic 2020년 11월 17일
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
Mario Malic
Mario Malic 2020년 11월 18일
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
Jason
Jason 2020년 11월 18일
Thankyou, this is what I was missing:
app.Slider2.ValueChangedFcn = createCallbackFcn(app, @SliderValueCback, true); % Creating callback, see function

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Develop uifigure-Based Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by