Change uiAxes DateNum to DateTime in AppDesigner for animatedLine Plot

Here, I have a UIAxes; with datenum tick marks. I have the values of x-ticks in String, as you can see from Time Field. I used datetickzoom and dynamicdateticks; but the zoom function gave error. Is there any possibility of changing these dateNum x-ticks to datetime ticks. It'll be better to use dynamic, but if there's no way for that, static vector ticks will also work.

 채택된 답변

Cris LaPierre
Cris LaPierre 2020년 6월 3일

0 개 추천

Can you convert your X data to datetime before plotting? Plots support datetimes as x values. You can convert a string to datetime using the datetime('06-Jun-2020 02:26:26') syntax.
You can use xtickformat function to format the datetime appearance.

댓글 수: 3

Yes, I can but the problem here is with animatedline (I'm not using plot function) that can't allow datetime values in argument.
% Draw Plot
try
if app.ShowAmpsCheckBox.Value == true
addpoints(h, datenum(x(k)), y(k, 1));
else
clearpoints(h);
end
if app.ShowUnitsCheckBox.Value == true
addpoints(j, datenum(x(k)), y(k, 2)); % I can't put datetime value in here
else
clearpoints(j);
end
catch
end
drawnow;
If I use this:
% Change X-Ticks to DateTime
%
% set(app.UIAxes, 'XTick', datenum(x(k)));
% datetick(app.UIAxes,'x','yyyy-mm-dd HH:MM:SS','keeplimits');
It gives a very bad looking plot.
Umair Mughal
Umair Mughal 2020년 6월 3일
편집: Umair Mughal 2020년 6월 3일
See everything works perfectly after using plot... As I zoom; it even shows the time in seconds.
If the appearance and labels are important, which I imagine they are, I would be inclined to suggest using plot instead of animatedline. Since I don't have your code, here's a simple example.
Somewhere, initialze the plot
l = plot(app.UIAxes,x(1),y(1,1))
Then, when you want to add points, update the XData and YData properties of your line object l.
l.XData = x(1:k);
l.YData = y(1:k,1);
And when you want to clear the points, you could do this.
l.XData = [];
l.YData = [];
I don't have your code, so you may need to do some slight modification to get this to work. If you are in app designer, you might also need to add l to your app properties, and reference it using app.l.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

제품

릴리스

R2020a

질문:

2020년 6월 3일

편집:

2020년 6월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by