How to print multiple strings in plot title?
23 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Mischa Kim
on 5 Mar 2014
Edited: Mischa Kim
on 5 Mar 2014
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 Comments
Mischa Kim
on 5 Mar 2014
Edited: Mischa Kim
on 5 Mar 2014
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.
See Also
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!