bug in sprintf 2024a, can't use other variable and just repeating the first variable
16 views (last 30 days)
Show older comments
this is the code that spoiled my food, I've been following this tutorial and I got stuck at this one for TWO HOURS! I can't use the second variable!
Nume = app.NumeratorEditField.Value;
Domi = app.DenominatorEditField.Value;
[r,p,k] = residue(Nume,Domi); % this is for partial fraction
r1 = real(r) %I am trying to seperate the real # from the imaginary number (complex)
r2 = imag(r) %I am trying to seperate the real # from the imaginary number (complex)
app.rTextArea.Value = sprintf('%g + %gi\n',r1, r2) %this is where I am stuck
%%% Instead of giving me the result:
0.23123 + -1.123123i
0.344 + 1.7766i
0.234 + 0.00251234i
%%% It is giving me this:
0.23123 + 0.23123i
0.344 + 0.344i
0.234 + 0.234i
-1.123123 + -1.123123i
1.7766 + 1.7766i
0.00251234 + 0.00251234i
Take note about the bold&italic numbers this might be clue ;(
PLEEASE HELP ME PASSED THIS COURSE ToT
0 Comments
Accepted Answer
Star Strider
on 6 Mar 2024
The residue funciton produces column vectors in its output. To use sprintf with them, concatenate them in a matrix and then transpose the matrix:
sprintf('%g + %gi\n',[r1, r2].')
Try this —
Nume = poly(randi(1,3))*10
Domi = poly(randi(1,4))*10
[r,p,k] = residue(Nume,Domi); % this is for partial fraction
r1 = real(r) %I am trying to seperate the real # from the imaginary number (complex)
r2 = imag(r) %I am trying to seperate the real # from the imaginary number (complex)
sprintf('%g + %gi\n',[r1, r2].') %this is where I am stuck
.
3 Comments
More Answers (0)
See Also
Categories
Find more on Characters and Strings in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!