3

I've a mat file with 24 variables inside and I would like to load only the 100 first value of the variables named Var1 and Var2 in the mat file.

tshepang
  • 12,111
  • 21
  • 91
  • 136

3 Answers3

2

Have a look at the matfile function (should be available from 2011b on). The documentation explains it pretty well.

obj = matfile('test.mat')
% save a variable
obj.foo = magic(30);
% load a variable
obj.foo(5:10,3:4)
beginner
  • 61
  • 2
  • I can't find the original release notes, but it [seems](http://blogs.mathworks.com/loren/2011/09/15/r2011b-is-available/) that it is available from 2011b on. Sry, I don't know about a ready-made solution for older versions. Maybe have a look at the Mathworks' File Exchange code sharing platform. – beginner Aug 29 '13 at 11:08
  • I've 2011a version :( – user2724407 Aug 29 '13 at 11:19
  • What I've done to load the first 100 value of VAR1 : load (Filename);i = strmatch('Var1',data.signals.labels,'exact'); tmp = data.signals.values(:,i); var1 = tmp(1:100,:); – user2724407 Aug 29 '13 at 11:50
  • @user2724407 Your are still loading the entire MAT file when calling `load(Filename)` – am304 Aug 29 '13 at 11:58
1

This utility on the File Exchange looks like it may do the job.

am304
  • 13,758
  • 2
  • 22
  • 40
0

In previous versions this is unfortunately not possible, see here

Best option would thus be to load in all variables and then create new variables containing only the first 100 values.

Fraukje
  • 673
  • 3
  • 20