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

Joseph Cheng
Joseph Cheng 2014년 3월 30일
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 2014년 3월 31일
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.

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

 채택된 답변

Joseph Cheng
Joseph Cheng 2014년 3월 31일

0 개 추천

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

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?

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

추가 답변 (0개)

카테고리

태그

질문:

2014년 3월 30일

댓글:

2014년 3월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by