Using slider to update a variable displayed in a text box
Mostrar comentarios más antiguos
Hi, I am writing a GUI code to plot rainfall of a given year. On the figure, I use a slider to allow the user to view the data at different times, and a text box to shows the starting and ending time of the period currently shown on the screen. I am unsure how to use the slider to update the date displayed in the text box. I am new to Matlab GUI, and would much appriciate if anyone can help with this problem. The code I got so far is as followed, and it does not the required task. Please help me because I really need it for my final thesis
function scrollplot3(dx,x)
a=gca;
data = guidata(a);
data.dx = dx;
stepratio = .1;
xmax = max(x);
xmin =min(x);
data.xmin = xmin;
data.xmax = max(xmax, xmin + dx);
data.dx = dx;
center = xmin;
set(gcf,'doublebuffer','on'); pos = get(a,'position'); pos = [pos(1) pos(2)-0.1 pos(3) 0.05];
S=['set(gca,''xlim'',get(gcbo,''value'')+[0 ' num2str(dx) '])'];
steptrough = dx / (data.xmax - data.xmin - dx);
steparrow = stepratio * steptrough;
a = uicontrol('style', 'slider',... 'units', 'normalized', 'position', pos, ... 'callback', S, ... 'min', data.xmin, 'max', data.xmax - dx, 'value', data.xmin, 'sliderstep',[steparrow steptrough]);
handles.text=uicontrol('Style','text',...
'Position',[200 65 300 20],...
'String',[num2str(datestr(data.xmin,'dd-mmm HH:MM:SS')),' ', num2str(datestr(data.xmax,'HH:MM:SS'))],'FontSize',12)
set(gca, 'xlim', center + [0 data.dx]);
1 comentario
Jan
el 15 de Abr. de 2012
Please explain "it does not the required task" explicitly.
Respuesta aceptada
Más respuestas (2)
Khoi Nguyen
el 17 de Abr. de 2012
Halima Mohamed Ismaeel Hasan Salman Altorabi
el 25 de Dic. de 2019
Editada: Halima Mohamed Ismaeel Hasan Salman Altorabi
el 25 de Dic. de 2019
This may help others who wants to update the text in a plot figure
I did it with help from this demo:
You can update the text appears in the scrollable plot figure after the plot command, by storing the reqired values in array with specifying the x and y dimentions
The text will appear on a specific points in the figure. The points are specified by"ennnd" array and the text is in "maxxx" array.
you can insted of text comand implement "annotation" command.
dx=7;
x=time;
y=signal;
a=gca;
p=plot(x,y);
beginnn=[];
ennnd=[];
maxxx=[];
[beginnn,ennnd,maxxx]=labelData(y,fs);
text(x(ennnd),y(ennnd),maxxx,'FontSize',16)
xlabel('Sec')
ylabel( 'mV');
title('ECG Raw data');
% Set appropriate axis limits and settings
set(gcf,'doublebuffer','on');
set(gcf, 'units','normalized','outerposition',[0 0 1 0.9]);
%% This avoids flickering when updating the axis
set(a,'xlim',[0 dx]);
set(a,'ylim',[min(y) max(y)]);
% Generate constants for use in uicontrol initialization
pos=get(a,'position');
Newpos=[pos(1) pos(2)-0.1 pos(3) 0.05];
%% This will create a slider which is just underneath the axis
%% but still leaves room for the axis labels above the slider
xmax=max(x);
S=['set(gca,''xlim'',get(gcbo,''value'')+[0 ' num2str(dx) '])'];
%% Setting up callback string to modify XLim of axis (gca)
%% based on the position of the slider (gcbo)
% Creating Uicontrol
h=uicontrol('style','slider',...
'units','normalized','position',Newpos,...
'callback',S,'min',0,'max',xmax-dx);
Categorías
Más información sobre Graphics Object Properties en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!