Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2024.0.0 - Português


matfile_varreadnext

Reads next variable in a Matlab binary MAT-file.

Syntax

[name, value, vartype] = matfile_varreadnext(fd)

Arguments

fd

file identifier (integer) as returned by matfile_open.

name

string: name of the returned variable, or "" if reading failed.

value

value of the variable read, or [] if reading failed.

vartype

integer: Matlab type of the variable if reading succeeds, or

  • 0: if the variable type is unknown.
  • -1: if end of file has been reached.
Please see matfile_listvar for the list of Matlab types.

Description

Reads next variable in a Matlab binary MAT-file opened with matfile_open.

Examples

// Preparing some data
H = rand(2,4,2);
N = complex(rand(2,3), rand(2,3));
I = int8(grand(4,10,"uin",-100,100));
T = ["foo" "bar"]';
S = struct("num",H, "imag",N, "text",T, "int",I);
C = {"Scilab", rand(2,3); H, S};

// Saving them
File = TMPDIR+"/matfile_listvar_example.mat";
savematfile(File,'-v7.3', 'H','N','I','T','S','C');

// Reading variables one by one:
fd = matfile_open(File, "r", "7.3");

//-- Loop on the stored variables
while %t
   [Name, Value, Type] = matfile_varreadnext(fd);
   if Type<0 then
      break
   else
      mprintf("The variable ""%s"" has type %d and contains\n", Name, Type);
      disp(Value);
   end
end
matfile_close(fd);
sleep(2000)
deletefile(File)
--> // Reading variables one by one:
--> fd = matfile_open(File, "r", "7.3");

--> //-- Loop on the stored variables
--> while %t
  >    [Name, Value, Type] = matfile_varreadnext(fd);
  >    if Type<0 then
  >       break
  >    else
  >       mprintf("The variable ""%s"" has type %d and contains\n", Name, Type);
  >       disp(Value);
  >    end
  > end
The variable "C" has type 1 and contains

  [  1x1 string  ]  [2x3 constant]
  [2x4x2 constant]  [1x1 struct  ]

The variable "H" has type 6 and contains

(:,:,1)
   0.2113249   0.0002211   0.6653811   0.8497452
   0.7560439   0.3303271   0.6283918   0.685731
(:,:,2)
   0.8782165   0.5608486   0.7263507   0.5442573
   0.068374    0.6623569   0.1985144   0.2320748

The variable "I" has type 8 and contains

  100  51 -52  92  17  34 -94 -30  36 -30
  -70 -72  -9 -19 -78 -15   1 -53 -23  91
   76 -83  93 -23  63 -80 -69  86  -7  57
   25  31  58 -64 -96  -9 -70  -4 -66 -34

The variable "N" has type 6 and contains

   0.2312237 + 0.2146008i   0.8833888 + 0.3616361i   0.3076091 + 0.5664249i
   0.2164633 + 0.312642i    0.6525135 + 0.2922267i   0.9329616 + 0.4826472i

The variable "S" has type 2 and contains

  num: [2x4x2 constant]
  imag: [2x3 constant]
  text: [2x1 string]
  int: [4x10 int8]

The variable "T" has type 4 and contains

!foo  !
!bar  !

See also

Bibliography

This function uses MATIO library ( http://sourceforge.net/projects/matio/ ).

Report an issue
<< matfile_open Matlab : Arquivos de dados (R/W) matfile_varwrite >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Tue Oct 24 14:35:32 CEST 2023