필터 지우기
필터 지우기

inserting numbers in a title of a plot

조회 수: 185 (최근 30일)
Brian
Brian 2011년 7월 23일
편집: syed kazim 2022년 11월 29일
Okay, I've written a piece of code that creates several plots of some data. I would like to be able to create a distinct title for each plot in the for loop shown below. I would like the title to be something like "False Load vs. Time on Day XXX of Test 1.0". Where XXX is an integer number corresponding to the day of testing. Is there any way to do this?
Thanks in advance!
x = 1:1440; x = x./60;
y = 1:8;
for i = 1:length(sure);
figure(i);
plot(x,safals(:,i))
title('False Load vs. Time on Day of Test 1.0');
xlabel('Time of Day [hrs]');
ylabel('False Load Power [Watts]');
axis([0 24 0 2600]);
hold;
end

답변 (2개)

Paulo Silva
Paulo Silva 2011년 7월 23일
Number=10; %the value you want to put on the title
title(['False Load vs. Time on Day ' num2str(Number) ' of Test 1.0'])
or use sprintf instead of num2str, the example I provided does string concatenation like this [string1 string2 string3 ...]
  댓글 수: 2
Brian
Brian 2011년 7월 23일
Thank you! This helped a lot. I've been trying the num2str function with little success until I noticed from your example that I forgot to insert the [] brackets. Duh! Thanks again!
Image Analyst
Image Analyst 2011년 7월 25일
That's why it's preferable (at least for me) to use sprintf instead.

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


syed kazim
syed kazim 2022년 11월 29일
편집: syed kazim 2022년 11월 29일
Title_1=append('False Load vs. Time on Day ', num2str(Number), ' of Test 1.0')
title(Title_1)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by