more than one input in sprintf

Hye, I would like to put two argument in sprintf.
I tried:
sprintf('mu=%s ,nu/omega=%s',mu1,q)
but it doesn't work, only the first one is assigned.

4 commentaires

Liber-T
Liber-T le 19 Juil 2011
The problem seams to be in this then:
FigH = figure;
set(FigH, 'NumberTitle', 'off','Name', sprintf('mu=%s ,nu/omega=%s',mu1,q));
Sean de Wolski
Sean de Wolski le 19 Juil 2011
That also works fine for me.
what does:
class(mu1)
class(q)
return?
Liber-T
Liber-T le 19 Juil 2011
double, for both.
Sean de Wolski
Sean de Wolski le 19 Juil 2011
that is your issue - they're doubles not strings. So you should be using %f or %g in your sprintf statement instead of %s which indicates class char. See both Walter's and my suggestions below.

Connectez-vous pour commenter.

 Réponse acceptée

Sean de Wolski
Sean de Wolski le 19 Juil 2011

0 votes

Works for me...
mu1 = 'hello world'
q = '78'
sprintf('mu=%s ,nu/omega=%s',mu1,q)
Remember you're calling it as a string so mu1 and q both have to be strings
Use %f or %g etc. for numbers that are not strings or convert the numbers to string using num2str
doc sprintf

Plus de réponses (1)

Walter Roberson
Walter Roberson le 19 Juil 2011

0 votes

That should work fine, provided that mu1 and q are both strings already.
Perhaps you want
sprintf('mu=%g, nu/omega=%g\n', mu1, q)

Catégories

En savoir plus sur Interactive Control and Callbacks dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by