Using a text file to title a plot.

I have a program that uses many different data sets to generate plots. In order to keep track of where each plot comes from I would like to pull the data set name out of an associated readme file. The trouble is that I can't seem to figure out how to insert the string I get from the readme. My code gets the string with a simple: label = textread(readme.txt, '%s'), but after getting the label I have not figured out how to successfully insert that label into my plot's title (printing label to the screen shows the desired output). Any suggestions?

댓글 수: 1

Joshua
Joshua 2011년 7월 13일
Thanks to Rick, as this works fine for a single line title. However, I had not noticed that it will not work for me as I am trying to create a two line title. One with the data set name and one with the name of the plot. I have tried using title({label,'x vs t'}) and ({label;'x vs t'}), but only get errors. Any thoughts on why these don't work?

댓글을 달려면 로그인하십시오.

 채택된 답변

Chirag Gupta
Chirag Gupta 2011년 7월 13일

0 개 추천

Try
title([label char(10) 'x vs y']) % char(10) for newline

댓글 수: 2

Chirag Gupta
Chirag Gupta 2011년 7월 13일
Also,
label ='random title'
title({label,'x vs y'})
should also work. Can you ensure that label is not a cell in your case
Joshua
Joshua 2011년 7월 13일
I cannot ensure that label is not a cell in this case, which is where I believe the problem was arising. However, the char(10) works perfectly. Thanks Chirag.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Rick Rosson
Rick Rosson 2011년 7월 13일

0 개 추천

The title function should work. For example:
figure;
plot(rand(50,1));
label = 'Some Random Numbers';
title(label);
HTH.
Sukuchha
Sukuchha 2011년 7월 13일

0 개 추천

you can also use like this: header{1} ='label'; header{2} ='x vs y'; title ( header)

카테고리

도움말 센터File Exchange에서 Axis Labels에 대해 자세히 알아보기

태그

질문:

2011년 7월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by