Append/Alter string in Title

I would like to append additional text to the title of a plot. How do I "get" the title string in order to append the added text and replace the title with the modified string?
The help tells me how to replace the title, but I want to add, say, a date, or filename.

 채택된 답변

Wayne King
Wayne King 2012년 5월 2일

1 개 추천

plot(randn(100,1));
h = title('Test');
origtitle = get(h,'String');
set(h,'String',[origtitle ' 2'])

댓글 수: 3

John Petersen
John Petersen 2012년 5월 3일
Thankyou! That helps. I use a function that plots a figure but does not return any handles. I can get the figure handle after it plots with get(gca), but is there a way to get the title handle with only the figure handle available? I could change the function to pass the plot handle, but then the calls to it would need to be changed and there might be other users.
Daniel Shub
Daniel Shub 2012년 5월 3일
The terminology matters here: Figure->Axis->Object. The gca function returns the handle to the current Axis, not the Figure. The plot handle (presumably the handle returned by plot), is a handle to an Object.
The axis object has a child object called Title. You can get this with h = get(gca, 'Title'). The h from this command will be identical to the h in Wayne's answer.
John Petersen
John Petersen 2012년 5월 3일
That clears up my followup question. Thankyou!

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

추가 답변 (0개)

카테고리

제품

태그

Community Treasure Hunt

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

Start Hunting!

Translated by