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: Etienne Grossmann
Subject: Re: reading in a matrix from a file
Date: Thu, 20 May 2004 17:54:07 -0400
User-agent: Mutt/1.4.2.1i

  Hi,

try this:

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

Explanation: "ordering of elements".

  The elements in the file are read row by row, left to right and
stored column by column, top to bottom.

  Hope that helps,

  Etienne

On Thu, May 20, 2004 at 05:30:06PM -0400, Rajarshi Guha wrote:
# 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
# -------------------------------------------------------------
# 

-- 
Etienne Grossmann ------ http://www.cs.uky.edu/~etienne



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