Search code examples
filematrixoctavenumerical-methods

octave error undefined near line 1 column 1


I try to read a matrix from a file. The code is very simple

function [mat] = read(file)

mat = load(file_points)

But when I try to run it

read('file')

mat =

scalar structure containing the fields:

mat =


   3  4  6
   3  5  1

it shows the matrix, but when I run this command...

>>mat(1,1)

error: 'points' undefined near line 1 column 1


Solution

  • From Octave Forge about load()

    If invoked with a single output argument, Octave returns data instead of inserting variables in the symbol table. If the data file contains only numbers (TAB- or space-delimited columns), a matrix of values is returned. Otherwise, load returns a structure with members corresponding to the names of the variables in the file.

    According to above, variable points is a (scalar) structure. However, if you use the_matrix_you_want = points.points; you would retrieve matrix.