HMS time with ERRORBAR plot

Hello,
I can't get any HMS times to work with errorbar, I've spent too much time on this and need help.
The example at:
Does works intermittently and if you zoom then the ticks don't auto adjust. If you click auto so the ticks can readjust then you will lose your HMS time.
Please assist,
Thank you.

Respuestas (1)

Walter Roberson
Walter Roberson el 11 de Mayo de 2017

0 votos

You could use a zoom ActionPostCallback https://www.mathworks.com/help/matlab/ref/zoom.html#brux2aq that did a datetick() call

7 comentarios

ZBMedina
ZBMedina el 23 de Mayo de 2017
Walter, Thanks for the input. Callbacks did work however once I closed out the figure and reopened later, the callback was no longer available. Its only available when I run the script inside of Matlab and don't close the figure. Hopefully Mathworks folks can figure out how to make errobar plots work with Datetime.
Walter Roberson
Walter Roberson el 24 de Mayo de 2017
Unfortunately zoom objects do not get saved with a figure if you savefig(). I thought for a moment the trick of setting the figure UserData to the zoom object would work, but unfortunately the restored zoom object does not have the information...
Ah, that's it. Set the axes CreateFcn to a little bit of code that adds in the zoom object. Then when the figure gets recreated with openfig(), the zoom object will be built along with the axes.
ZBMedina
ZBMedina el 19 de Mayo de 2020
Can you provide an example of the CreateFcn? Having some difficultly trying to get more info about it. I was hoping Mathworks would have fixed this issue by now but it doesn't seems to be the case. Thanks!
function axes3_CreateFcn(hObject, event)
handles = guidata(hObject);
if ~isfield(handles, 'zoom_obj') || ~isvalid(handles.zoom_obj)
handles.zoom_obj = zoom(ancestor(hObject, 'figure'));
handles.zoom_obj.ActionPostCallback = @(hObject, event) datetick(handles.axes3, 'x');
guidata(hObject, handles);
end
end
ZBMedina
ZBMedina el 20 de Mayo de 2020
Thank you!
Got it to work however I have to choose between datetick for format or xticks for resetting the number of tick marks. Can both be used on the following line following @(hObject, event)? Thanks!
handles.zoon_obj.ActionPostCallback = @(hObject, event) datetick(event.Axes, 'x','HH:MM:SS.FFF', 'keepticks'); and also xticks(linspace(min(xlim(event.Axes)),max(xlim(event.Axes)),25));
Walter Roberson
Walter Roberson el 21 de Mayo de 2020
invoke a function passing in event that does both items for you.
It could be written without a true function (.m) by adding two helper anonymous functions, but there probably is no point in that.
ZBMedina
ZBMedina el 21 de Mayo de 2020
It worked!!! I wish I would have understood what you mentioned 3 years ago.
I added an additional IF statement for pan aswell, seems to work.
Matlab didn't like ~invalid so i used isvalid instead and that seems to not crash.
Thanks again!

Iniciar sesión para comentar.

Categorías

Preguntada:

el 11 de Mayo de 2017

Comentada:

el 21 de Mayo de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by