How to add multiple indices to graph title, legend, and output image?
6 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Amit Davidi
2012-2-2
The last line should be:
print(f,'-dtiff', sprintf('GRAPH_%d_INDJ_%d_INDK_%d',i,j,k))
更多回答(2 个)
Walter Roberson
2012-2-2
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?
Amit Davidi
2012-2-2
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)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!