Path: news.mathworks.com!newsfeed-00.mathworks.com!panix!bloom-beacon.mit.edu!llnews!53ab2750!not-for-mail
From: Peter Boettcher <boettcher@ll.mit.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Complex structure to text file
References: <f9fq2l$2vi$1@fred.mathworks.com>
Message-ID: <muyhcj78osx.fsf@G99-Boettcher.llan.ll.mit.edu>
Organization: MIT Lincoln Laboratory
User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/23.0.0 (gnu/linux)
Cancel-Lock: sha1:0ESXxoKULH0XcKHaRZUxXKHqq7Q=
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Lines: 21
Date: Tue, 27 Nov 2007 14:35:10 -0500
NNTP-Posting-Host: 155.34.163.114
X-Complaints-To: news@ll.mit.edu
X-Trace: llnews 1196191686 155.34.163.114 (Tue, 27 Nov 2007 14:28:06 EST)
NNTP-Posting-Date: Tue, 27 Nov 2007 14:28:06 EST
Xref: news.mathworks.com comp.soft-sys.matlab:439709


"Jamie James" <jamie.james.nospam@mathworks.com> writes:

> Hello Rick,
>
> I have been loking at you solution for writing complex 
> data in a file using fprintf. That will work well, if your 
> imaginary number is always positive.
>
> I am in the same situation, but my imaginary number might 
> change a sign, then using the solution posted on web, e.g.,
> gives me a+-jb, what I will be looking for a-jb
>
> Could you please help, to write complex structure in a 
> file for negative imaginary number.

fprintf('%f%+fi\n', real(x), imag(x));

The trick is the %+f flag, which says print the sign of the variable,
even if it's plus.

-Peter