real & imaginary part
26 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
sina arfaee
am 23 Feb. 2019
Beantwortet: John D'Errico
am 23 Feb. 2019
Hi
My output is like (0.000 + 1.000i).
How I can show output without real part and like (1i)?
It is important that the output contain i.
Thanks a lot
0 Kommentare
Akzeptierte Antwort
John D'Errico
am 23 Feb. 2019
There is not a display or command window preference that will allow you to do as you have indicated.
X = rand + i*rand
X =
0.981596208916383 + 0.496799421779149i
real(X)
ans =
0.981596208916383
imag(X)*i
ans =
0 + 0.496799421779149i
But now, you want to see this without the 0 real part. The thing is, if you create the number as imaginary, MATLAB sees it as complex. So it displays a zero real part.
I suppose nothing stops you from using sprintf though. So something like this?
sprintf('%.15fi',imag(X))
ans =
'0.496799421779149i'
Or this
disp(sprintf('%.15fi',imag(X)))
0.496799421779149i
Or
disp([num2str(imag(X),15),'i'])
0.496799421779149i
To do something more sophisticated than that, you would need to overload disp & display to intercept the result when your input has an imaginary part but no real part.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Entering Commands finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!