How to get a non integer value from uicomponent slider (Jslider) in Matlab?

2 views (last 30 days)
I have written this function in Matlab (using a function from the Matlab File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/14583-uicomponent-expands-uicontrol-to-all-java-classes)
function [] = fun()
figure
slider = uicomponent('style','slider', 'position',[50,50,200,45], ...
'value',0.0, 'MajorTickSpacing',2, ...
'MinorTickSpacing',1, 'Paintlabels',1, ...
'PaintTicks',1, 'Orientation',0);
slider.Minimum = -2.05;
slider.Maximum = 2.25;
slider.StateChangedCallback = @myMatlabFunction;
function myMatlabFunction(o,~)
disp(get(o, 'value'))
end
end
When I move the slider, I only get an integer values. I'd like to get floating-point values, e.g., 2.1. How?

Answers (1)

Suman Saha
Suman Saha on 7 Aug 2013
function [] = ANALOGCOMM(action) if nargin<1, action='initialize'; end; if strcmp(action,'initialize') close all; figure
sld1Hndl=uicontrol('Style','slider','Tag','sl','Units','inches', ... 'Position',[3 2-0.4 1 0.3],'BackgroundColor',0.6*[0 1 1],'Callback','ANALOGCOMM(''build'')'); uicontrol('Style','text','String','Amplitude','Units','inches','FontName','monotype corsiva', ... 'Position',[3 2 1 0.4],'BackgroundColor',0.3*[0 0 1],'FontSize',15,... 'ForegroundColor',0.9*[1 0 1]); uicontrol('Style','text','Tag','sld','String',' ','Units','inches','FontName','monotype corsiva', ... 'Position',[3 1.1 2 0.4],'BackgroundColor',0.3*[0 0 1],'FontSize',15,... 'ForegroundColor',0.9*[1 0 1]); elseif strcmp(action,'build') VALUE=50; %Change the value & see changes A=VALUE*get(findobj(gcf,'Tag','sl'),'Value'); set(findobj(gcf,'Tag','sld'),'String',sprintf('%f Volt',A));
end

Categories

Find more on Interactive Control and Callbacks 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!