Can I see the values that at the slider ?

7 visualizaciones (últimos 30 días)
metin eroglu
metin eroglu el 24 de Abr. de 2019
Comentada: Adam Danz el 24 de Abr. de 2019
Hello,
Can I see or can I get the values that at the slider ?
Untitled.png
You can see the slider tabs and I need to see the values at the slider. For instance, the value of the top is 0.75, and I need to see 0,75 at the gui panel. Can you help me?
Thank you

Respuesta aceptada

Adam Danz
Adam Danz el 24 de Abr. de 2019
You can access the slider value from the handle to the slider. I don't know if you're using 'guide' or 'appdesigner' (or neither) but you'll use the same method either way. Here's a demo
fig = uifigure;
h = uislider(fig);
% h is the handel to your slider
sliderValue = h.Value;
If you want to display that on your GUI you'll need to add a static text box that displays the value.
  4 comentarios
metin eroglu
metin eroglu el 24 de Abr. de 2019
Hello again my friend, I did it success with different way I think. I just add that code.
Here, my value is stored in "sliderVal". and I just write that
set ( handles.text38,'String',sliderVal);
So all code is that :
function slider5_Callback(hObject, eventdata, handles)
% hObject handle to slider5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
global im_adjust_low
sliderVal = get ( hObject , 'Value' ) ;
% set ( handles.testNum, 'String', num2str (sliderVal) ) ;
% factor = num2str (sliderVal) ;
im_adjust_low = (sliderVal) ;
%handles.text38.String = sprintf('%.1f', sliderVal); % round to 1 dp
set ( handles.text38,'String',sliderVal);
Thank you again broadening my horizon : )
Adam Danz
Adam Danz el 24 de Abr. de 2019
I see. Newer versions of matlab allow for dot notation to access properties instead of set() and get(). More info: https://www.mathworks.com/help/matlab/creating_plots/access-and-modify-property-values.html
That's one difference in your line of code. The other difference is that I converted the sliding value to a string and rounded to 1 decimal place whereas you're entering the value directly as text. Both methods are OK.
Congrats for solving it!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by