help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: reading in a matrix from a file


From: Hall, Benjamin
Subject: RE: reading in a matrix from a file
Date: Thu, 20 May 2004 17:41:59 -0400

Try:

fd = fopen('fptest.txt','r');
[xt,cnt] = fscanf(fd,"%d", [10,18])';   # Swap the 10 and 18, add the
transpose at end
fclose(fd)

You can (at least I do) think of the fscanf() function as reading in a
string of 18*10 = 180 numbers, then reshaping the output to your requested
size.  It might be helpful to play with a smaller matrix, say 3x4 or
something like that and reading it in both ways to see the differences.

Ben



-----Original Message-----
From: Rajarshi Guha [mailto:address@hidden
Sent: Thursday, May 20, 2004 5:30 PM
To: address@hidden
Subject: reading in a matrix from a file


Hi,
  I'm a new user of Octave and I'm having a strange problem reading in
a matrix from a file. An example is below:

0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0 0 0
0 0 0 0 1 0 1 0 0 1
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0

I'm doing:

fd = fopen('fptest.txt','r');
[xt,cnt] = fscanf(fd,"%d", [18,10]);
fclose(fd)

However when I look at xt I get 

  0  0  1  0  0  0  0  0  0  0
  0  0  0  0  0  1  0  0  0  0
  0  0  0  0  0  0  0  0  0  0
  0  0  1  0  0  0  0  0  0  0
  0  0  0  0  0  0  0  0  0  0
  0  0  0  0  0  0  0  0  0  0
  0  1  0  0  0  0  0  0  0  0
  0  0  0  0  0  0  0  0  0  0
  0  0  0  0  0  0  0  0  0  0
  0  0  0  0  0  0  0  0  0  0
  0  0  0  0  0  0  0  0  0  0
  0  0  0  0  0  0  0  0  0  0
  0  0  0  0  0  0  0  0  0  0
  0  0  0  0  0  0  0  0  0  0
  0  0  0  0  0  0  0  0  0  0
  0  0  0  0  0  0  0  0  0  0
  0  1  0  0  0  0  0  0  0  0
  0  0  0  0  0  0  0  0  0  0

I can't see where I'm going wrong and why the fscanf is not giving me
the right result.

Could anybody shed any pointers?

Thanks,

-------------------------------------------------------------------
Rajarshi Guha <address@hidden> <http://jijo.cjb.net>
GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE
-------------------------------------------------------------------
A method of solution is perfect if we can forsee from the start,
and even prove, that following that method we shall attain our aim.
-- Leibnitz



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]