From help-request at octave dot org Thu May 20 17:01:49 2004 Subject: Re: reading in a matrix from a file From: Etienne Grossmann To: Rajarshi Guha Cc: help at octave dot org, etienne@cs.uky.edu Date: Thu, 20 May 2004 17:54:07 -0400 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 # 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 -------------------------------------------------------------