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: Geordie McBain
Subject: Re: reading in a matrix from a file
Date: Fri, 21 May 2004 09:38:50 +0200
User-agent: KMail/1.5.4

The matrix can be read in without transposition by using load() instead of 
scanf():

        octave> load "fptest.txt"

This stores the matrix in a new variable called fptest.

> -----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
> -------------------------------------------------------------



-------------------------------------------------------------
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]