How to print multiple strings in plot title?
23 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Mischa Kim
el 5 de Mzo. de 2014
Editada: Mischa Kim
el 5 de Mzo. de 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 comentarios
Mischa Kim
el 5 de Mzo. de 2014
Editada: Mischa Kim
el 5 de Mzo. de 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.
Ver también
Categorías
Más información sobre Characters and Strings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!