How to print multiple strings in plot title?
23 ビュー (過去 30 日間)
古いコメントを表示
My code plots many figures, and I use it for different data sets individually (i.e. run the code for site 1 data, clear all, run for site 2 data, etc.). I want the plots to have titles with two parts: a phrase that will change from time to time (e.g. site = 'site 1'), and a phrase that will remain the same (e.g. Monthly Wind Speed); title should read 'Site 1 Monthly Wind Speed'. I'd like to not change every plot's title each time I use a different data set. Any ideas on how to do this?
0 件のコメント
回答 (1 件)
Mischa Kim
2014 年 3 月 5 日
編集済み: Mischa Kim
2014 年 3 月 5 日
Matt, use strcat to individually define (concatenate) strings as plot titles. As an example
for ii = 1:N
...
str = strcat({'Site '}, num2str(ii),' Monthly Wind Speed');
title(str);
...
end
2 件のコメント
Mischa Kim
2014 年 3 月 5 日
編集済み: Mischa Kim
2014 年 3 月 5 日
OK. Something like:
Sites = {'Florida', 'Georgia', 'Texas'};
filename = 'Florida.txt'; % your data file
[pathstr,name,ext] = fileparts(filename); % extract file name
ii = find(ismember(Sites,name)); % find pos in Sites array
str = strcat(Sites{ii},{' Monthly Wind Speed'});
title(str)
Alternatively, you could simply use name in the strcat command. The above approach you'd use if you are working with more complicated file names from which you need to extract the site name.
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!