Search code examples
matlabplotmatlab-figure

Figure Matlab: title desappears


When executing:

x=1:100;
figure(1)
title('Sobel software execution scalability')

I obtain:

enter image description here

But, when I plot something, executing for example:

x=1:100;
figure(1)
title('Sobel software execution scalability')
plot(x)

The result is this other one:

enter image description here

The figure is present but the title is disappeared. What am I doing wrong?

The solution I have found is to add hold on:

x=1:100;
figure(1)
title('Sobel software execution scalability')
hold on
plot(x)

but it sounds really strange. Is it possible that I need to add hold on all the time? What if I need to change the figure runtime??

Note that these few lines were written just for you to replicate the error on your host machine.


Solution

  • The answer is: print the title after plot. Otherwise, plot will overwrite what was on the figure before.