'Octave - fskipl: invalid stream number

I've got the error message: "Invalid parameter list" from my function, which let Octave open a text file and read it to get input data for my work.

function [machNumbers]=readsrm(testfile.txt) 
  fid = fopen('testfile.txt','w');
  fskipl(fid, 3);

  # read number of machnumber
  numMachNumber = fscanf(fid, "%i", 1)
  fscanf(fid, "%s", 5);
  machNumbers = fscanf(fid, "%f", numMachNumber);

  fclose(fid);
endfunction

EDIT:

I've updated my code and now I've got this Error: "error: fskipl: invalid stream number = -1".

My code Looks like this:

function [machNumbers, weights, altitudes, specificRanges]=readsrm(myfilename)
myfilename = "filename"

  fid = fopen(myfilename,'r');
  fskipl(fid, 3);

fclose(fid);
endfunction

EDIT:

The Problems above are solved, thank you. :) Now is the Problem that my for-loop doesn't work correctly. With that code I don't get any Parameters from my text file.

Here is the code:

function [machNumbers, weights, altitudes, specificRanges]=readsrm(myfilename)
myfilename = "testfile.txt"

  fid = fopen(myfilename,'r');
  fskipl(fid, 3);

  # read number of machnumber
  numMachNumber = fscanf(fid, "%i", 1)
  fscanf(fid, "%s", 5);
  machNumbers = fscanf(fid, "%f", numMachNumber);

  # read weights
  numWeights = fscanf(fid, "%i", 1);
  fscanf(fid, "%s", 5);
  weights = fscanf(fid, "%f", numWeights)

  # rad altitudes 
  numFl = fscanf(fid, "%i", 1)
  fscanf(fid, "%s", 5);
  altitudes = fscanf(fid, "%f", numFl)

  irrelevantValues = fscanf(fid, "%s", 7)
  for flightLevel= 1:numFl
    for weight = 1:numWeights
      specificRanges(flightLevel, weight, 1:numMachNumber) = fscanf(fid, "%f", numMachNumber);
    endfor
  endfor
  fclose(fid);
endfunction


Solution 1:[1]

function [machNumbers]=readsrm(testfile.txt) 

isn't a valid function declaration. You want to give a valid variable name, for example

function [machNumbers]=readsrm(myfilename)
  fid = fopen(myfilename,'r');
  ...

and then call your function as

machNumbers = readsrm("testfile.txt");

and of course you apparently want to read from fid, so you have to fopen the file with "r"(read access), not with "w"(write access)

Solution 2:[2]

For me double quotes around the file name caused my issue.

Try switching to single quotes.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Andy
Solution 2 Gerry