How to add text to legend

13 views (last 30 days)
James
James on 12 Mar 2013
How do I add the text "C" after my entries on the legend. For example my legend displays the two input numbers. I want these to display as "Input# C". This is my script:
tC1=input('Enter the first temperature in °C:');
tC2=input('Enter the second temperature in °C:');
tK1=(tC1)+(273.15);
tK2=(tC2)+(273.15);
n=1;
R=8.314;
v=0:1:1000;
pkPa1=(n*R*tK1)./v;
pkPa2=(n*R*tK2)./v;
loglog(v,pkPa1);
loglog(v,pkPa2,'r--');
ylim([0 1000])
grid on;
title('Title');
xlabel('Volume');
ylabel('Pressure');
legend(num2str(tC1),num2str(tC2));<----This is my problem

Answers (2)

Walter Roberson
Walter Roberson on 12 Mar 2013
legend( sprintf('%f C', tC1), sprintf('%f C', tC2) )

Azzi Abdelmalek
Azzi Abdelmalek on 12 Mar 2013
legend({num2str(tC1),num2str(tC2)})
  1 Comment
James
James on 12 Mar 2013
How can I add "C" to the end of the data on the legend? i.e. "25 C". I already have the "25" part. You just enclosed what I already had in another parenthesis.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!