Path: news.mathworks.com!newsfeed-00.mathworks.com!NNTP.WPI.EDU!elk.ncren.net!newsflash.concordia.ca!canopus.cc.umanitoba.ca!not-for-mail
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Newsgroups: comp.soft-sys.matlab
Subject: Re: Complex structure to text file
Date: Tue, 27 Nov 2007 19:05:27 +0000 (UTC)
Organization: National Research Council Canada - Conseil national de rechereches Canada
Lines: 33
Message-ID: <fihppn$ipt$1@canopus.cc.umanitoba.ca>
References: <f9fq2l$2vi$1@fred.mathworks.com> <f9fug7$9lq$1@fred.mathworks.com> <f9futi$fmb$1@fred.mathworks.com> <fihp3k$sau$1@fred.mathworks.com>
NNTP-Posting-Host: origin.ibd.nrc.ca
X-Trace: canopus.cc.umanitoba.ca 1196190327 19261 192.70.172.160 (27 Nov 2007 19:05:27 GMT)
X-Complaints-To: abuse@cc.umanitoba.ca
NNTP-Posting-Date: Tue, 27 Nov 2007 19:05:27 +0000 (UTC)
Originator: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Xref: news.mathworks.com comp.soft-sys.matlab:439707


In article <fihp3k$sau$1@fred.mathworks.com>,
Jamie James <jamie.james.nospam@mathworks.com> wrote:

Please do not post your reply at the top of what you are
commenting on: it makes it more difficult to hold a conversation.

>> > "Rick Rosson" <rrosson@mathworks.com> wrote in message
>> > <f9ftl6$qgi$1@fred.mathworks.com>...

>> >>     for k = 1:L
>> >>         fprintf(fid,'%f + %f%c ',real(X(k)),imag(X
>> > (k)),imchar);
>> >>         fprintf(fid,'\n');
>> >>
>> >>     end

>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

signs = '-++';

for k = 1:L
   fprintf(fid, '%f %c %f%c ', real(X(k)), signs(2+sign(imag(X(k)))), ...
           imag(X(k)), imchar)
end
fprintf(fid, '\n');

sign(x) is -1, 0, or 1; add 2 to that to take it to the range
1 2 3, which you then index into the signs() table of characters
to print out to indicate the sign.
-- 
  "All is vanity."                                   -- Ecclesiastes