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

조회 수: 1 (최근 30일)
Sunil  Shahi
Sunil Shahi 2013년 7월 31일
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