Datetime bug in R2016b when saving figure that has a legend

1 次查看(过去 30 天)
I am running Matlab R2016b and have a figure that is plotting a datenum class vector vs a vector of doubles (see sample script below). When running the code, if "legend show" is commented out, the code runs successfully and my figure is saved and able to be re-opened. If "legend show" is un-commented, I receive the error "Caught "std::exception" Exception message is: Access violation - no RTTI data!" and my figure is not saved. If I try to save the figure by clicking File >> Save and save as *.fig, I receive the error "Error while evaluating menu Callback". Saving as *.png or *.bmp is successful. I've run the same script in Matlab 2015a and it did not exhibit this bug (i.e. saving as a *.fig was successful).
Also, for what it's worth, R2016b auto-formats the x-axis into HH:MM:SS format, while R2015a formats as HH:MM (this is not problematic, just an observation).
Code:
clear all; close all; clc;
seconds_since_epoch = 1963156824:1:1963157000;
x = datetime(seconds_since_epoch,'ConvertFrom','epochtime','Epoch','1904-01-01');
y = 1:length(x);
figure;
plot(x,y)
legend show
savefig(gcf,'untitled.fig')
  1 个评论
Michael
Michael 2017-2-8
I have exactly the same problem with Matlab R2016b wiht a figure, where a duration class vector vs a double class vector is plotted.

请先登录,再进行评论。

回答(3 个)

Peter Perkins
Peter Perkins 2017-1-6
This seems to be a sporadic issue, and I've made a note to have it looked into. You should see a bug report posted sometime soon. Using 'compact' in your call to savefig should avoid the error:
savefig(f,'myfig_legend.fig','compact')
Hope this helps.
  2 个评论
Charles Boardman
Charles Boardman 2017-2-9
I have the same issue using R2016b on Windows 7 64 bit machine. Plotting time series data. Trying to save the figure results in "Error while evaluating Menu Callback" or if you use the savefig command then "Access violation - no RTTI data!.
This only occurs when there is a legend in the figure.
The existing bug report does not provide enough detail to be able to reproduce the issue.

请先登录,再进行评论。


Lionel
Lionel 2017-1-5
I have the same issue, without the legend I am able to save the figure in .fig but not with it. I am running the following version of Matlab : R2016b(9.1.0.441655). Thanks for the help.
dt = (datetime+minutes(0:60))';
y = rand(size(dt));
f = figure;
plot(dt,y,'DisplayName','rand')
savefig(f,'myfig.fig') % working fine
legend('show')
savefig(f,'myfig_legend.fig') % error
Error : Caught "std::exception" Exception message is: Access violation - no RTTI data!

Peter Perkins
Peter Perkins 2016-12-2
Kristin, I can't reproduce this in R2016b on either windows or mac. Is it possible you're using a pre-release version of R2016b?

类别

Help CenterFile Exchange 中查找有关 Legend 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by