Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check the contents of a MAT-file in MATLAB without loading it?

I have a large structure in a MAT-file. I want to check if a specific field is present in the structure without loading the MAT-file since the contents are very large and I want to minimize memory use.

Is this possible, or must I load it first like in the following example?:

load('test.mat');             %# Load the MAT-file
tf = isfield(s,'fieldname');  %# Check if structure s has field 'fieldname'
like image 461
Elpezmuerto Avatar asked Oct 26 '10 18:10

Elpezmuerto


People also ask

How can I see the content of a mat file?

Previewing MAT-File Contents To see what variables are stored in a MAT-file before actually loading the file into your workspace, use whos -file filename . This command returns the name, dimensions, size, and data type of all variables in the specified MAT-file.

How do I view a .MAT file in MATLAB?

On the Home tab, in the Environment section, click Preferences. Select MATLAB > General > MAT-Files.

Can I open mat file without MATLAB?

. mat files contain binary data, so you will not be able to open them easily with a word processor. There are some options for opening them outside of MATLAB: If all you need to do is look at the files, you could obtain Octave, which is a free, but somewhat slower implementation of MATLAB.

How do you call a mat file in MATLAB?

To load a subset of variables from a MAT-file on the Home tab, in the Variable section, click Import Data. Select the MAT-file you want to load and click Open. You also can drag the desired variables from the Current Folder browser Details panel of the selected MAT-file to the Workspace browser.


1 Answers

To check the contents of a MAT file without loading it, use:

vars = whos('-file','test.mat')
ismember('fieldname', {vars.name})
like image 160
Amro Avatar answered Nov 01 '22 17:11

Amro