Print figure without its title

35 ビュー (過去 30 日間)
MichailM
MichailM 2020 年 2 月 23 日
編集済み: Star Strider 2020 年 2 月 24 日
Having the simple code example below:
close all;
clear all;
clc;
x = rand(10,1);
y = rand(10,1);
f1 = figure(1);
plot(x,y,'*')
title('Random title')
print(f1,'-dpng', 'testpng', '-r600');
The "print" function will save the generated figure in my directory including the figure title. Is there any way I can save the figure without the title while keeping the "title" finction in my code for display purposes?
EDIT:
Consider there is no option to re-arrange the code lines. Please see updated code example below
close all;
clear all;
clc;
x = rand(10,1);
y = rand(10,1);
n = 0;
f(n+1) = figure(n+1);
plot(x,y,'*b')
title('Random title 1')
n = get(gcf,'Number');
f(n+1) = figure(n+1);
plot(x,y,'*r')
title('Random title 2')
n = get(gcf,'Number');
f(n+1) = figure(n+1);
plot(x,y,'*g')
title('Random title 3')
n = get(gcf,'Number');
figpr = input(['Please insert which figure to print (<',num2str(n),'): ']);
print(f(figpr),'-dpng', 'testpng', '-r600');

回答 (2 件)

Star Strider
Star Strider 2020 年 2 月 23 日
編集済み: Star Strider 2020 年 2 月 24 日
One option is to keep the title in the figure call. See Specify Figure Title for an example.
Another option is:
title('Random title', 'Color','none')
You could set the 'Color' value as a variable, and then change it to whatever you want whenever you want.

Giuseppe Inghilterra
Giuseppe Inghilterra 2020 年 2 月 23 日
Hi,
an easy and fast solution could be save first the figure and then add title, as following code:
close all;
clear all;
clc;
x = rand(10,1);
y = rand(10,1);
f1 = figure(1);
plot(x,y,'*')
print(f1,'-dpng', 'testpng', '-r600');
title('Random title')
This should solve your problem.
  1 件のコメント
MichailM
MichailM 2020 年 2 月 23 日
Yes, this does the job but ideally I would like to do that without rearranging the order of the code lines.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by