Write results to text file???

  • Follow


I know the general way to write to a text file but now I want it in a certain format

Say i have two numbers that I want to get reported (a and b)

file1 = fopen('output1.txt','w') %Open to write to output1.txt
fprintf(file1, '    ')

%In the (' ') I dont know how to display a and b in a way that in the textfile, it will look like this:

a|b|    %The (|) look like thin, small black rectangle, don't know what to call it.
0
Reply Judas 4/19/2010 5:55:10 AM

On 19 apr, 07:55, "Judas Magnus" <ragnaork5...@yahoo.com> wrote:
> I know the general way to write to a text file but now I want it in a cer=
tain format
>
> Say i have two numbers that I want to get reported (a and b)
>
> file1 =3D fopen('output1.txt','w') %Open to write to output1.txt
> fprintf(file1, ' =A0 =A0')
>
> %In the (' ') I dont know how to display a and b in a way that in the tex=
tfile, it will look like this:
>
> a|b| =A0 =A0%The (|) look like thin, small black rectangle, don't know wh=
at to call it.

All of this is explained in the documentation of the
FPRINTF function. First find the docs. Then read them.
Last, contemplate what you read.

Rune
0
Reply Rune 4/19/2010 8:57:37 AM


Judas Magnus wrote:
> I know the general way to write to a text file but now I want it in a 
> certain format
> 
> Say i have two numbers that I want to get reported (a and b)
> 
> file1 = fopen('output1.txt','w') %Open to write to output1.txt

As an aside: because you are writing in text format, you should use 'wt' 
instead of 'w'.

> fprintf(file1, '    ')
> 
> %In the (' ') I dont know how to display a and b in a way that in the 
> textfile, it will look like this:
> 
> a|b|    %The (|) look like thin, small black rectangle, don't know what 
> to call it.

fprintf(file1, '%f|%f|\n', [a(:),b(:)].' );

You may wish to experiment with %d and %g instead of %f .
0
Reply Walter 4/19/2010 3:01:57 PM

2 Replies
364 Views

(page loaded in 0.099 seconds)

Similiar Articles:













7/22/2012 6:56:27 AM


Reply: