GUI show only last 5 values in plot
4 次查看(过去 30 天)
显示 更早的评论
Hello everyone! I am working on a GUI that is supposed to display and log data from a pressure sensor. The writing of the Logfile already works fine; The display should be done on two ways: one "digital" display that shows the current value (I am just updating a static text in the GUI) and a Graph that shows the last n values in a yx-Graph. For the latter I modified a script from the fileexchange that does almost exactly what i wanted, only that it kind of compresses the x-Axis with every new y-value in order to show them all. Since I just want the last n values to be shown, i thougt it would be easiest to redefine xlim with every new pressure value.
It kind of works, but the graph now "flips" between showing only the last 5 values and all of them (with a compressed x-Axis). I have no Idea why it does that, it seems that after each loop the XlimMode is set to auto before i redefine xlim again.
Would be really thankful if someone had a clue for me
As you can see from my code below i am an absolute beginner in Matlab programming, so I am open, thankful and happy about any suggestions optimizing the code as well.
kind regards, Pavel
P.s. heres the part of the GUI where i am stuck.:
% --- Outputs from this function are returned to the command line.
function varargout = Controler_GUI_OutputFcn(hObject, eventdata, handles)
global Exitflag;
global Writeflag;
global Filename;
global Filenamepath;
global Depth;
startline=2;
column='A';
count=1;
%%Set up Figure
time=now; % initialising "time"
Depth=rand(1);%Initialising "Depth"
plotHandle = plot(handles.axes1,time,Depth,'Marker','.','LineWidth',2,'Color','blue');%[0 0 0]);
xlim('manual');
%xlim(handles.axes1,[min(time) max(time+0.5)]);
while Exitflag==1; % Value controlled by pushbutton
Depthwrite=rand(1);% Simulating Data input--> Insert request here
set(handles.text2,'String',Depthwrite); % Display Depth in "static String" Display
if Writeflag==1; % ...then record data & display Data in Graph --> Controlled by a toggle button
% Display Graph
if count<5;
xlim(handles.axes1,[time(1) time(numel(time))+0.5]); % Until I have at least 5 Values in Depth, show theam all
Depth(count)=Depthwrite;
time(count) = datenum(clock);
set(plotHandle,'YData',Depth,'XData',time);
datetick('x','mm/DD HH:MM');
else
xlim(handles.axes1,[time(count-4) time(count-1)]); %From here only show the last 5 Values
Depth(count)=Depthwrite;
time(count) = datenum(clock);
set(plotHandle,'YData',Depth,'XData',time);
datetick('x','mm/DD HH:MM');
end
% Write Excel-File
Data={Datestr(now,'yyyy-mm-dd'),datestr(now,'HH:MM:SS'),Depthwrite}; % 1by2 Array for Excel recording
xlswrite(Filenamepath,Data,Filename,strcat(num2str(startline),column));
startline=startline+1;
count=count+1;
end
guidata(hObject, handles);
pause(1);
end varargout{1} = handles.output;
0 个评论
采纳的回答
bym
2011-8-21
don't know if it will help, but explore the use of
drawnow()
also, be aware of the datetick options 'keeplimits' and 'keepticks'
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!