Incorrect TimeZone displayed on plot
Show older comments
Working on a simple plot of time of day (hrs - on the x-axis) and arbitrary data on the y-axis in the App Designer. Whatever the initial plotted time zone was, will be the time zone even if I change it.
In this example, I create a time matrix of time starting on 15 March, 2023 from midnight to midnight (24 hrs). The y-data is arbitrary but is the same size as the time matrix.
After running the app, you select one of the "time zone" buttons to set either 'UTC' or 'UTC-8' as the global timezone variable, then you hit plot. After plotting initially, you can change the timezone again by hitting the other button and plotting. However, the timezone on the x-axis remains the initial timezone.
The only way I could fix this is by clearing the plot or axes after each plot. This is very clumsy and slow. What am I missing?
Here is the part of the app I created. I attached the app for others to try out.
properties (Access = private)
timezone % Global timezone variable
end
methods (Access = private)
function PlotFunction(app)
time_init = datetime(2023,3,15);
time_init.TimeZone = app.timezone;
time_addition = hours(0:1:24);
time = time_init + time_addition;
x = 0:1:24;
y = sin(x);
plot(app.UIAxes,time,y)
xtickformat(app.UIAxes,'HHmm z')
end
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: PlotButton
function PlotButtonPushed(app, event)
app.PlotFunction
end
% Button pushed function: SetZuluButton
function SetZuluButtonPushed(app, event)
app.timezone = 'UTC';
end
% Button pushed function: SetUTC8Button
function SetUTC8ButtonPushed(app, event)
app.timezone = '-8';
end
end
1 Comment
Timothy Sick
on 13 Feb 2023
Accepted Answer
More Answers (0)
Categories
Find more on Language Fundamentals in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!