Path: news.mathworks.com!not-for-mail
From: "Jamie James" <jamie.james.nospam@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Complex structure to text file
Date: Tue, 27 Nov 2007 18:53:40 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 143
Message-ID: <fihp3k$sau$1@fred.mathworks.com>
References: <f9fq2l$2vi$1@fred.mathworks.com> <f9fsgh$a17$1@fred.mathworks.com> <f9fstg$ft6$1@fred.mathworks.com> <f9ftl6$qgi$1@fred.mathworks.com> <f9fug7$9lq$1@fred.mathworks.com> <f9futi$fmb$1@fred.mathworks.com>
Reply-To: "Jamie James" <jamie.james.nospam@mathworks.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1196189620 29022 172.30.248.38 (27 Nov 2007 18:53:40 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 27 Nov 2007 18:53:40 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1197369
Xref: news.mathworks.com comp.soft-sys.matlab:439705


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.

Thanks in advance.
Jamie  



"Rick Rosson" <rrosson@mathworks.com> wrote in message 
<f9futi$fmb$1@fred.mathworks.com>...
> 
> Glad to help.
> 
> There is some additional formatting you can do with the 
FPRINTF function. 
> Take a look at the help for how to adjust the spacing 
and precision of the 
> numerical outputs.  Type
> 
>     doc fprintf
> 
> at the command prompt, or search for "fprintf" in the 
Help Browser.
> 
> Rick
> 
> 
> 
> "Anthony " <anthony.campos@baesystems.com> wrote in 
message 
> news:f9fug7$9lq$1@fred.mathworks.com...
> > That worked great. I had to change the 'w' to 'wt' 
because
> > it wasn't showing right in notepad. Thanks for your 
help
> >
> > "Rick Rosson" <rrosson@mathworks.com> wrote in message
> > <f9ftl6$qgi$1@fred.mathworks.com>...
> >> Hi Anthony,
> >>
> >> I send the previous solution before I saw your latest
> > response.  To create a
> >> file with one number on each line, try the following:
> >>
> >>
> >>     imchar = 'i';
> >>
> >>     L = length(X(:));
> >>
> >>     filename = 'myData.txt';
> >>     fid = fopen(filename,'w');
> >>
> >>     for k = 1:L
> >>         fprintf(fid,'%f + %f%c ',real(X(k)),imag(X
> > (k)),imchar);
> >>         fprintf(fid,'\n');
> >>
> >>     end
> >>
> >>     fclose(fid);
> >>
> >>
> >> I hope that helps.
> >>
> >> Thanks.
> >>
> >> Rick
> >>
> >>
> >>
> >> "Anthony " <anthony.campos@baesystems.com> wrote in
> > message
> >> news:f9fstg$ft6$1@fred.mathworks.com...
> >> > It would be nice to have one complex number per 
row, in
> > the
> >> > following format:
> >> > a + bi
> >> >
> >> > "Rick Rosson" <rrosson@mathworks.com> wrote in 
message
> >> > <f9fsgh$a17$1@fred.mathworks.com>...
> >> >> Hi Anthony,
> >> >>
> >> >> It is definitely possible to write complex numbers 
to a
> >> > text file, but the
> >> >> exact syntax depends on how you want to format the
> >> > numbers.
> >> >>
> >> >>   1. Do you want to show the numbers as strings
> > using "i"
> >> > or "j"
> >> >>      to represent the imaginary unit?  For example:
> >> >>
> >> >>         2.512 + 3.718i    OR
> >> >>         2.512 + 3.718j
> >> >>
> >> >>   2. How do you want the numbers delimited?  In 
other
> >> > words, do
> >> >>      you want to separate each element with a 
space, a
> >> > comma, a
> >> >>      tab, or some other character?
> >> >>
> >> >> Thanks.
> >> >>
> >> >> Rick
> >> >>
> >> >>
> >> >> "Anthony " <anthony.campos@baesystems.com> wrote in
> >> > message
> >> >> news:f9fq2l$2vi$1@fred.mathworks.com...
> >> >> >I am trying to take a data that's in a matrix in
> > matlab
> >> > and
> >> >> > output it to a file.  In each cell there is a 
complex
> >> >> > number. Is there a way to write this complex 
number
> > to a
> >> >> > file? and maintain the precision, or change the
> >> > precision?
> >> >>
> >> >>
> >> >
> >>
> >>
> > 
> 
>