🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.soft-sys.matlab
2 messages
2 total messages Started by Rob Thieler Thu, 01 Sep 1994 14:29
help: formatting matlab vectors/columns with fprintf
#161
Author: Rob Thieler
Date: Thu, 01 Sep 1994 14:29
39 lines
2318 bytes
Greetings. I've got a little problem in matlab 4.1.1 that's driving me
nuts. Recourse to the manual and the FAQ hasn't helped.

I have a matrix called L12_030794_bathy_corr. It looks like:

>> size(L12_030794_bathy_corr)

ans =

   864     9

I want to save this as an ascii file called "L12_030794_bathy_corr.dat"
using a printf of the form

'%.6f\t%.6f\t%.1f\t%02.0f\t%02.0f\t%02.0f\t%06.4f\t%.8f\t%.1f\n'

where each %.Xf refers to the desired format of vectors/columns 1-9 in
the matrix.

So far, my attempts have met with spectacular failure. I
get a flat file of the data in the each column formatted according to
each of the nine specs in serial fashion. I must be doing something
dumb here.  I'm assuming that this command would behave like a printf
in C or awk (i.e., print each row using format #1 for $1, #2 for $2,
etc.) but obviously this is not the case. Can someone help me out?

The commands I've been using are:

fid = fopen('L12_030794_bathy_corr.dat','w');

fprintf(fid,'%.6f\t%.6f\t%.1f\t%02.0f\t%02.0f\t%02.0f\t%06.4f\t%.8f\t%.1
f\n', L12_030794_bathy_corr);

Thanks in advance,

Rob Thieler                               | rthieler@rogue.geo.duke.edu
Duke University, Department of Geology    |         Tel: (919) 681-8228
Pgm for the Study of Developed Shorelines |         Fax: (919) 684-5833
Durham, NC  27708-0228                    |
Re: help: formatting matlab vectors/columns with fprintf
#162
Author: Cleve Moler
Date: Thu, 01 Sep 1994 19:34
35 lines
1740 bytes
In article <344ofl$970@news.duke.edu>,
Rob Thieler <rthieler@rogue.geo.duke.edu> wrote:
>Greetings. I've got a little problem in matlab 4.1.1 that's driving me
>nuts. ...
>
>The commands I've been using are:
>
>fid = fopen('L12_030794_bathy_corr.dat','w');
>
>fprintf(fid,'%.6f\t%.6f\t%.1f\t%02.0f\t%02.0f\t%02.0f\t%06.4f\t%.8f\t%.1
>f\n', L12_030794_bathy_corr);
>
>Rob Thieler

Hi

I think all you need to add is one apostrophe to transpose your matrix:

 fprintf(fid,'%.6f\t... \n', L12...corr');
                                       ^--   that's it, there.

When you say

 fprintf(fid,'format',A)

the matrix A is sent to the print routine column by column, just
like A(:).  The format is used over and over again until all the data
has been processed.  Since you are thinking of the format as 
describing a row, not a column, use

 fprintf(fid,'format',A')

Hope this is what you were after.

  -- Cleve Moler
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads