Function to display variables in MATLAB figures

조회 수: 28 (최근 30일)
Rohan
Rohan 2011년 8월 16일
Say I have to plot the following:
x = [3 4 5 6]; y = [6 7 8 9];
Say in some logic these vectors hold their value for 'case1' which holds an integer value 10 (say).
Now I want this integer -10 i.e. value of 'case1' to display when I plot a MATLAB figure say using plot(x,y). Is there a function that will insert this value onto my plot?
Thank you

답변 (1개)

Chirag Gupta
Chirag Gupta 2011년 8월 16일
Where do you want to insert this in the plot? You can insert this as a point on the existing graph using:
hold on;
plot(-10,1,'xk'); % Whats the y coordinate for -10 ?
If you just want to insert it to annotate your graph, you can use:
hold on;
text(2,3,'case1: -10');
If you want to place this as the title:
title(['case 1:' num2str(-10)]);
  댓글 수: 2
Rohan
Rohan 2011년 8월 16일
Aplogies the '-' in the pos was to stand for hiphun and not negative sign.
Yeah I want to have it as a title. So does the num2str function display the value '10' on the plot screen title if I did the following?
plot(x,y);
Case_val = 10;
title(['case 1' num2str(Case_val)]);
Cheers
Chirag Gupta
Chirag Gupta 2011년 8월 16일
should! If you want the quotes around the the number then:
title([' case 1: ''' num2str(val) '''']);

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

카테고리

Help CenterFile Exchange에서 Title에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by