Can array values be used in plot titles?

I'm really sorry I can't be more specific and include any code, but this is for an assignment and so it would be wrong to publish my code.
However, this is quite a generic question so I hoped this time it would not be a problem.
I have a figure with 5x2 plots on, and each of the ten plots correspond to a different frequency, which are generated by one entered value (not frequency).
Is it then possible to have those generated values (currently in an array) appear in the titles of each subplot?

 採用された回答

José-Luis
José-Luis 2012 年 11 月 8 日

0 投票

a = 1:10;
all_titles = arrayfun(@(x) {num2str(x)},a);
h = cell(1,10);
for ii = 1:10;
h(ii) = {subplot(1,10,ii)};
end
cellfun(@(x,y) set(get(x,'title'),'string',y),h,all_titles)

その他の回答 (1 件)

Arthur
Arthur 2012 年 11 月 8 日

0 投票

Use num2str and title.

5 件のコメント

Tom
Tom 2012 年 11 月 8 日
Okay that's a good start thanks. The frequencies are all in one value - 'freq' - which looks like [500 1000 2000 etc.] So using that method gets me one string with 10 frequency values in it. How do I create 10 different strings from 'freq'?
José-Luis
José-Luis 2012 年 11 月 8 日
編集済み: José-Luis 2012 年 11 月 8 日
a = 1:10;
all_titles = arrayfun(@(x) {num2str(x)},a);
Tom
Tom 2012 年 11 月 8 日
Thanks again - I must be doing something wrong though. Here's the section of code that's relevant.
clear all; close all;
f_max = 950;
freq = [f_max/10,f_max/4,f_max/1.5,f_max/1.1,f_max*1.1,...
f_max*1.2,f_max*1.3,f_max*2,f_max*3,f_max*4];
freq_n = numel(freq);
freq_i = 1:10;
all_titles = arrayfun(@(freq) {num2str(freq)},freq_i);
I'm getting all_titles coming out as a cell with just 1,2,3..10 in it.
Arthur
Arthur 2012 年 11 月 8 日
You want to make titles from the array 'freq'? Then it should be
all_titles = arrayfun(@(x) {num2str(x)},freq);
Tom
Tom 2012 年 11 月 9 日
Many thanks Arthur & Jose-Luis.

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

カテゴリ

製品

質問済み:

Tom
2012 年 11 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by