how to define random values of slider?

1 view (last 30 days)
how to define random values of slider by varying it and show in text box? In my coding it shows only the value 1. Coding is attached.
  2 Comments
Joseph Cheng
Joseph Cheng on 30 Mar 2014
Can you upload the code? nothing shows up. It is not clear on what you are trying to achieve with random numbers and the slider.
  1. slider contains random numbers
  2. Max value of slider is random.
  3. or other
Mina
Mina on 31 Mar 2014
I have attached the code with my question. Its a notepad file. I need some random values when i move slider but i only get 1 whenever i move it.

Sign in to comment.

Accepted Answer

Joseph Cheng
Joseph Cheng on 31 Mar 2014
This will be a 2 part solution. To answer your only get 1 you'll need to do something like this.
Button1 = uicontrol('Style', 'pushbutton', 'String', 'Run',...
'Position', [450 30 100 30],'Callback', {@edit_val,Slider1});
and then add an additional input to the function.
function edit_val(hobject, event,Slider1)
You are correct and the uicontrol passes the hobject and event, but those are for the uicontrol you are creating. Here the edit_val is not getting slider and event for the specified slider1. It is receiving the hobject and event for the associated pushbutton. I've included the Slider1 to pass the handle for slider1. Since we did that we need to add it to the function as an additional input.
I'm still thinking on how to get the random numbers within the sliders.
  1 Comment
Joseph Cheng
Joseph Cheng on 31 Mar 2014
To get random values for the steps you can do something like this
Slider1 = uicontrol('Style', 'slider', 'Min',0,'Max', 10,...
'Position', [80 20 180 30],'Callback', @randomize);
Then have a function
function randomize(hobject, event)
disp(get(hobject,'Value'));
rando = 10*rand(1);
set(hobject,'Value',rando);
where whenever something is moved you set it to a random number between 0 and 10?

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!