- slider contains random numbers
- Max value of slider is random.
- or other
how to define random values of slider?
1 view (last 30 days)
Show older comments
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
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.
Accepted Answer
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
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?
More Answers (0)
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!