How to print multiple strings in plot title?
조회 수: 25 (최근 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!