How to add multiple indices to graph title, legend, and output image?

6 views (last 30 days)
Motivation: I want to automatize the loading, processing and output of multiple data. Indices such as i, j, k, etc... are used to distinguish them. The output should have the same input indices.
Example: For the case of one data (graph and output image), I have the following command lines:
i=5;
f=figure(i);
x = 0:pi/100:2*pi;
y = sin(x-i);
h=plot(x,y);
legend(h,sprintf('sin(x-%d)',i),1);
title(['GRAPH\_',num2str(i)]);
print(f,'-dtiff', ['IMAGE_',num2str(i)]);
PROBLEM: I have multiple indices and I want that all of them be part of graph title and image name, so I changes the lines above intuitively to:
i=5;
j=3;
k=7;
f=figure(i,j,k);
x = 0:pi/100:2*pi;
y = j*sin(k*x-i);
h=plot(x,y);
legend(h,sprintf('%d*sin(%d*x-%d)',j,k,i),1);
title(['GRAPH_%d_INDJ_%d_INDK_%d',num2str(i,j,k)]);
print(f,'-dtiff', ['GRAPH_%d_INDJ_%d_INDK_%d',num2str(i,j,k)])
I expected to obtain:
graph title: GRAPH_5_INDJ_3_INDK_7; and
image name: GRAPH_5_INDJ_3_INDK_7,
where indices(IND)5 3 and 7 are part of titles and names.
But unfortunately I obtain the following error:
??? Error using ==> figure
Too many input arguments.
f=figure(i,j,k);
So I wonder if someone could help me to correct these line so that I obtain what I expect.
Thank you in advance for your help
Emerson

Accepted Answer

Amit Davidi
Amit Davidi on 2 Feb 2012
The last line should be:
print(f,'-dtiff', sprintf('GRAPH_%d_INDJ_%d_INDK_%d',i,j,k))

More Answers (2)

Walter Roberson
Walter Roberson on 2 Feb 2012
figure gets passed the single figure number of the figure to create. What would you like to have happen with the triple index, taking in to account that figure numbers can only be integers and not vectors?
  1 Comment
Emerson De Souza
Emerson De Souza on 2 Feb 2012
Walter, I understand your comment.
All what I want to do is to name the graph and output image using
indices, because I don't want to change them manually every time one by one.
What I want to happen is:
I write the indices:
i=5
j=2
k=7
and wish that these numbers be part of the graph name:
title('graphi_parameterj_parameterk'),
and name of output image:
print -dtiff imagei_parameterj_parameterk
My lines worked for one index, but I don't know how to extend to multiple indices.
I hope you have an idea how to solve the problem.
Thanks
Emerson

Sign in to comment.


Amit Davidi
Amit Davidi on 2 Feb 2012
If I understand you correctly, I don't think you need to number the figure. You can just use:
f = figure;
By the way, once you'll solve this error, you're expected to get another one... You use twice this line:
['GRAPH_%d_INDJ_%d_INDK_%d',num2str(i,j,k)]
You should replace with:
sprintf('GRAPH_%d_INDJ_%d_INDK_%d',i,j,k)
  1 Comment
Emerson De Souza
Emerson De Souza on 2 Feb 2012
The following lines
i=10;
j=4;
k=5;
f=figure;
x = 0:pi/100:2*pi;
y = j*sin(k*x-i);
h=plot(x,y);
box on
title(sprintf('GRAPH %d INDJ %d INDK %d',i,j,k));
sprint(f, '-dtiff','GRAPH %d INDJ %d INDK %d',i,j,k);
solves the problem with the name of the graph, but it does not save this image to the hard disk. I obtain the following error for the last line:
??? Undefined function or method 'sprint' for input
arguments of type 'double'.
By the way, to only name the graph, I don't need f=figure at all.
Hope you know a way to SAVE the image.
Thanks
Emerson

Sign in to comment.

Categories

Find more on Images in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!