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

1 次查看(过去 30 天)
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?

回答(1 个)

Suman Saha
Suman Saha 2013-8-7
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

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by