I have tried using the same metamorphosis with the RH active as well. I get the same results.
After some more testing, it seems like setting the XAxis explicitly seems to cause the issue. Even if I delete the lines and redraw them, if I set the XAxis to a different ruler rather than letting plot do it, I still get errors:
Error:
% Create a figure
f = figure;
ax = axes(f);
% Initialize the right Y
yyaxis(ax,'right');
% Plot something on the left
yyaxis(ax,'left');
line1 = plot(ax,1:10,1:10);
% Plot something on the right
yyaxis(ax,'right')
line2 = plot(ax,1:10,(1:10).^2);
% Make the left Y active again
yyaxis(ax,'left');
% Change to datetime
% Some new x data
newX = datetime(2022,9,1:10);
% Delete the exisitng lines
delete(line1);
delete(line2);
% Set the XAxis ruler to be a datetimeruler
ax.XAxis = matlab.graphics.axis.decorator.DatetimeRuler;
% Redraw the lines
yyaxis(ax,'left');
line1 = plot(ax,newX,1:10);
% Plot something on the right
yyaxis(ax,'right')
line2 = plot(ax,newX,(1:10).^2);
Works:
% Create a figure
f = figure;
ax = axes(f);
% Initialize the right Y
yyaxis(ax,'right');
% Plot something on the left
yyaxis(ax,'left');
line1 = plot(ax,1:10,1:10);
% Plot something on the right
yyaxis(ax,'right')
line2 = plot(ax,1:10,(1:10).^2);
% Make the left Y active again
yyaxis(ax,'left');
% Change to datetime
% Some new x data
newX = datetime(2022,9,1:10);
% Delete the exisitng lines
delete(line1);
delete(line2);
%%%%% This was the line that caused the error!!!
% Set the XAxis ruler to be a datetimeruler
% ax.XAxis = matlab.graphics.axis.decorator.DatetimeRuler;
% Redraw the lines
yyaxis(ax,'left');
line1 = plot(ax,newX,1:10);
% Plot something on the right
yyaxis(ax,'right')
line2 = plot(ax,newX,(1:10).^2);