LoadML4Matrix

Declaration: LoadML4Matrix (IFile: TFileStream; Offset: integer; var DataArr: TDouble2DArray; var MName: string): integer;
The function LoadML4Matrix loads a particular matrix specified by the parameter Offset from the MatLab 4 formatted file stream IFile. The variable array DataArr returns the corresponding array. The parameter MName returns the name of this matrix.

The function returns the following error codes:

 0 ... everything OK
-1 ... there is no valid info header at the given offset

Sample program: The following code lets you select a MatLab file. If the selected MatLab file is stored in MatLab 4 format, the first matrix of the file is loaded into the variable DataMat and printed:

program readml4;

var
  FName          : string;
  fs             : TFileStream;
  datamat        : TDouble2DArray;
  offsets        : TIntArray;
  nMats          : integer;
  MatName        : string;

begin
FName := SelectFile ('', '*.mat', 'Please select a MatLab 4 file');
if FName <> '' then
  begin
  fs := TFileStream.Create (FName, fmOpenRead);
  NMats := CountML4Matrices (fs, Offsets);
  if NMats > 0 then
    begin
    LoadML4Matrix(fs, Offsets[0], datamat, MatName);
    cout ('DataMat: ', datamat);
    end;
  fs.Free;
  end;
end.