How can I load part of a .mat file that is too big in memory for my machine?

混江龙づ霸主 提交于 2019-12-18 04:11:34

问题


I have a big .mat file that I want to process, but it is too big to fit in a single load. I thought to load it in parts, each time to access just the important parameters. So I have practically two questions:

  1. How can I access the variables names of the mat file without loading it?
  2. How can I load only one of them to the workspace?

Thanks!


回答1:


you can see the list of variables using:

vars = whos('-file','name.mat');

and then just load the variable you want, say the first one on the list, by:

load('name.mat', vars(1).name)



回答2:


As well as loading individual variables from the .mat file as suggested by @natan, in recent versions of MATLAB you can use a matfile object to load in only parts of an individual variable.

So for example, you can say:

myFile = matfile('path\to\the\mat\file');
loadedData = myfile.myVarName(100:200, 500:600);

and you will load in only a portion of the variable myVarName from the file myFile.


Edit:

The matfile object also has methods size, who and whos, so that you can determine the names and sizes of the variables that the file contains before you attempt to load bits in.



来源:https://stackoverflow.com/questions/17518940/how-can-i-load-part-of-a-mat-file-that-is-too-big-in-memory-for-my-machine

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!