How to insert a complex root in a text using fprintf?
Afficher commentaires plus anciens
Hi, I'm new to matlab and could use some help regarding a pretty basic commando. This is my hypotethical problem:
*>> a = [1 0 4]
a =
1 0 4
>> b = roots(a)
b =
0 + 2.0000i
0 - 2.0000i
>> c = num2str(b)
c =
0+2i 0-2i
>> d1 = c(1,:)
d1 =
0+2i
>> d2 = c(2,:)
d2 =
0-2i
>> fprintf('One root is: %g',d1) One root is: 48One root is: 43One root is: 50One root is: 105>>*
I would like the fprintf commando to print: One root is: 0+2i But for some reason I get a very weird print :/ Thanks in advance.
Réponses (1)
Titus Edelhofer
le 25 Nov 2011
Hi,
you will need to print real and imaginary part seperately:
fprintf('One root is %g %+g i\n', real(d1), imag(d1));
Titus
Catégories
En savoir plus sur Entering Commands 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!