Group Abstract Group Abstract

Message Boards Message Boards

2
|
20.6K Views
|
3 Replies
|
5 Total Likes
View groups...
Share
Share this post:

Concatenate a string with a variable?

Posted 9 years ago

I want to annotate a Plot3D or a Plot with the clause:

PlotLabel-> "c=" <> c

where c is a variable that has been assigned a numeric value. I get the error message,

StringJoin::string : String expected at position 2 in c = <> 150.

I have tried several other syntaxes, to no avail:

PlotLabel-> StringJoin["c=", c]
PlotLabel->"c=" <> StringForm[c]
PlotLabel-> StringJoin["c=", InputForm[c]]

Does anyone know know to do this in Mathematica?

POSTED BY: Herbert Swan
3 Replies

Marco is precise, this is the way. A small note for the future. PlotLabel formats as TraditionalForm so if you need advanced blend of strings and typesetting you could use Row:

Plot[Sin[3 x], {x, 0, 20}, PlotLabel -> Row[{"C=", Integrate[f[x] BesselJ[x, Pi], {x, a, b}]}]] 

enter image description here

POSTED BY: Vitaliy Kaurov

Thank you very much!

POSTED BY: Herbert Swan

What about this?

c = 0.3;
Plot[Sin[c x], {x, 0, 20}, PlotLabel -> "C=" <> ToString[c]]

enter image description here

Cheers,

M.

POSTED BY: Marco Thiel
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard