1

I've a mat file which when loaded gives me something like this:

train0:[1200x300] train1:[1450x300] . . . . . . trainN:[Nx300]

what I want to do is traverse over each matrices in a manner like train+"i" where i = 0 to N and create a NX1 matrix with value of i. Here N will be the number of rows in each of the train matrices.

gizgok
  • 7,303
  • 21
  • 79
  • 124

1 Answers1

1

try loading the file into a sturct

ld = load(matfilename);
numRow = structfun( @(x) size(x,1), ld );

A more complicated method might be:

ld = load(matfilename);
matNames = fieldnames( ld );
numRows = zeros( 1, numel(matNames) );
for fi = 1:nueml(matNames)
    tkn = regexp( matNames{fi}, '^train(\d+)$', 'tokens', 'once' );
    ii = str2double( tkn{1} );
    numRows(ii) = size( ld.(matNames{fi}), 1 );
end

Anyhow, loading the mat file into a struct allows you to manipulate all loaded matrices as struct fields.

Shai
  • 111,146
  • 38
  • 238
  • 371