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

2 vues (au cours des 30 derniers jours)
Sunil  Shahi
Sunil Shahi le 31 Juil 2013
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?

Réponses (1)

Suman Saha
Suman Saha le 7 Août 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
  1 commentaire
Jan
Jan le 7 Août 2013
Please explain the relation between this code and the question.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by