is there anyway i could get the slider to update the limit to the image count Ct?
It seems that the app.Slider.Limits only accepts numerical values - at the moment it is set at 2. How can in incorperate the .Count function into the slider limit so the limit automatically updates with the value of .Count should i decide to import another file with a different .Count value?
How can I add a listener function here also?
Imported imageSet code
% Button pushed function: LoadImageButton
function LoadImageButtonPushed(app, event)
global Ct
imgSetVector = imageSet(uigetdir(''),'recursive');
Z = read(imgSetVector,1);
Ct = imgSetVector.Count;
imshow(Z,'Parent',app.UIAxes)
Slider Code
app.Slider = uislider(app.UIFigure);
app.Slider.Limits = [1 2]; **
app.Slider.MajorTicks = [];
app.Slider.MajorTickLabels = {''};
app.Slider.ValueChangedFcn = createCallbackFcn(app, @SliderValueChanged, true);
app.Slider.MinorTicks = [];
app.Slider.Position = [296 36 321 3];
app.Slider.Value = 1;
Thanks!

 Respuesta aceptada

Ameer Hamza
Ameer Hamza el 5 de Mayo de 2020

1 voto

Try to set the slider limit after this line
Ct = imgSetVector.Count;
app.Slider.Limits(2) = Ct;

11 comentarios

Thanks for the reply!
I tried modifying the code as you mentioned:
app.Slider = uislider(app.UIFigure);
app.Slider.Limits(2) = Ct;
app.Slider.MajorTicks = [];
app.Slider.MajorTickLabels = {''};
app.Slider.ValueChangedFcn = createCallbackFcn(app, @SliderValueChanged, true);
app.Slider.MinorTicks = [];
app.Slider.Position = [296 36 321 3];
app.Slider.Value = 1;
However I got the error:
Unable to perform assignment because the left and right sides have a different number of elements.
Ameer Hamza
Ameer Hamza el 5 de Mayo de 2020
Not here. You need to assign it in LoadImageButtonPushed. So that the limits are changed when you push the button.
Pranaya Kansakar
Pranaya Kansakar el 5 de Mayo de 2020
Do i cut out the
app.Slider.Limits(2) = Ct;
from this section or revert back to the original code (shown in the first post)?
Ameer Hamza
Ameer Hamza el 5 de Mayo de 2020
Remain the slider code the same as in the question. Just try to change it in the callback.
Pranaya Kansakar
Pranaya Kansakar el 5 de Mayo de 2020
Editada: Pranaya Kansakar el 5 de Mayo de 2020
That's great - it worked!
Thanks!
Do you know if it's possible to create a listener function to the slider?
Ameer Hamza
Ameer Hamza el 5 de Mayo de 2020
The slider has value changed and value changing callbacks. You can use that to respond to change in slider value. In app-designer. right click the slider and in callback menu, create the type of callback you want.
Pranaya Kansakar
Pranaya Kansakar el 5 de Mayo de 2020
Hmm... the code that I edited appears to be a .m file as opposed to a .mlapp file.
How can I open the .m file in app deisgner?
Sorry i'm new to Matlab!
Image Analyst
Image Analyst el 5 de Mayo de 2020
Right. I don't think there's any need for a listener since you know every place where it might need updating.
Pranaya Kansakar
Pranaya Kansakar el 5 de Mayo de 2020
Editada: Pranaya Kansakar el 5 de Mayo de 2020
Thanks everyone for bearing with me.
I guess i'm trying to say is there any way of updating the slider value without lifting the mouse click?
I guess this issue is addressed in the following link (by creating a plot that automatically responds):
However, this webpage demonstrates sliders using the "uicontrol" function instead of "app".
Ameer Hamza
Ameer Hamza el 5 de Mayo de 2020
The valueChanging callback for uislider does not require lifting the mouse button. Read here: https://www.mathworks.com/help/releases/R2020a/matlab/ref/uislider.html#buicpgg-1_sep_shared-ValueChangingFcn.
Why are you creating the app in a script? Isn't it easier to use the app-designer?
Pranaya Kansakar
Pranaya Kansakar el 5 de Mayo de 2020
Editada: Pranaya Kansakar el 5 de Mayo de 2020
I didn't realise that you could use the code in app-designer as well.
I've implemented it in app-designer and it works great!
Thanks!
I guess this was a trivial issue.
I attach my interpretation of the app if anyone else in the future stumbles across the same problem.
*it's laggy...

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Interactive Control and Callbacks en Centro de ayuda y File Exchange.

Productos

Versión

R2020a

Preguntada:

el 5 de Mayo de 2020

Editada:

el 5 de Mayo de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by