Helping adding Tittle to Plot (multititle)

Hello,
I have a contour plot and i need a title like that for it:
"my title" variable1 variable2
My title is a character string always the same, but variable1 and variable2 change with every plot.
I have tried this:
title('my title', variable1, variable2);
But it did not work.
Error in ==> title at 55
set(h, 'String', string, pvpairs{:});
I also want to add units to the colourbar and a legend
Thank you very much!

 채택된 답변

Star Strider
Star Strider 2015년 1월 5일

0 개 추천

If ‘variable1’ and ‘variable2’ are strings, this works:
variable1 = 'Velocity';
variable2 = 'Position';
figure(1)
scatter(rand(10,1), rand(10,1), 'bp')
title(sprintf('“My Title“ %s %s', variable1, variable2))

댓글 수: 10

Peter
Peter 2015년 1월 5일
variable1 and variable2 are numbers
In that instance, just change the format descriptor to the version and precision of your choice:
title(sprintf('“My Title“ %.3f %.3f', variable1, variable2))
See the documentation for fprintf and its friends for a full list of available format descriptors.
Peter
Peter 2015년 1월 5일
Thanks, but if i write that My Tittle appears together with variable1 and variable2 two times.
When I use single numbers for both, it works the way it should:
variable1 = pi;
variable2 = exp(1);
figure(1)
scatter(rand(10,1), rand(10,1), 'bp')
title(sprintf('“My Title” %.3f %.3f', variable1, variable2))
Are ‘variable1’ and ‘variable2’ vectors? If so, you may have to subscript them in a loop:
for k1 = 1:2
figure(k1)
scatter(rand(10,1), rand(10,1), 'bp')
title(sprintf('“My Title” %.3f %.3f', variable1(k1), variable2(k1)))
end
Peter
Peter 2015년 1월 5일
No. They are numbers and "My Title" appears repeated before each variable...
I really do not understand why.
Peter
Peter 2015년 1월 5일
편집: Peter 2015년 1월 5일
Your solution should work, but it does not (neither changing %f by %d)
I am trying:
title(['X 230mm ',num2str(important), num2str(Uinff)]);
but then important and Uinff (my variables) appear together!! :(
I need to see your variables and the way they are stored. Something is strange about them.
Also, your new idea will run the numbers together. You have to add a string of a few blank spaces between the numbers to separate them:
title(['X 230mm ' num2str(important) ' ' num2str(Uinff)]);
Peter
Peter 2015년 1월 5일
편집: Peter 2015년 1월 5일
EUREKA
Thank you very much! That was a syntaxis problem with the blank spaces
My pleasure!
UCRMechanicalEngineer
UCRMechanicalEngineer 2016년 6월 29일
편집: UCRMechanicalEngineer 2016년 6월 29일
Thank you, this helped me.

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

추가 답변 (1개)

Julian Hapke
Julian Hapke 2015년 1월 5일

0 개 추천

title(['my title' var1 var2])
depending on the variable type, you may have to convert to string and add separators like whitespace when concatenating.

댓글 수: 1

Peter
Peter 2015년 1월 5일
adding separators like whitespace does not work, the variables appears together

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

카테고리

태그

질문:

2015년 1월 5일

편집:

2016년 6월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by