MATLAB: How to make sure that axes properties retain its values after using PLOT function in MATLAB

MATLAB

When I execute the following code:
axes;
set(gca,'tag','tag1');
plot(1:10);
get(gca,'tag')
I receive the following result:
ans=
' '
I would like to see "tag1" as the result.

Best Answer

PLOT command automatically clears most properties of the current axes.
'Tag' is one of the properties that refreshes after executing the PLOT command.
To work around this issue, use the HOLD ON command. For example:
axes;
set(gca,'tag','tag1');
hold on
plot(1:10);
hold off
get(gca,'tag')