How does MATLAB run load, importdata, matfile functions

조회 수: 3 (최근 30일)
Shih-Hsuan Yuan
Shih-Hsuan Yuan 2017년 1월 25일
댓글: Shih-Hsuan Yuan 2017년 1월 25일
Hi,
I am wondering if anyone knows the actual process MATLAB run function load and matfile. I have a .mat file with a single variable that consists of a column of cells.
I try loading with both function
load(full_path)
and
temp_file = matfile(full_path);
data = temp_file.data;
I am using MATLAB R2015a and on my machine, the second method with matfile usually out performs the first one (load faster). It seems weird to me. I try opening both function and look at their code, but unfortunately they are built-in functions. I am wondering if anyone knows what is the reason behind this. Thanks

채택된 답변

Jan
Jan 2017년 1월 25일
Depending on the format of the MAT file (see e.g. Level-5-mat-format, mat-file-versions) different methods are applied to import the file. E.g. the HDF5 format of 7.3 MAT-files can be accessed by other tools also and not only by built-in functions.
Your 2nd approach, which catches the output in a variable migth be faster, because the dynamic create of variables by load without output argument impedes the efficient processing.
  댓글 수: 1
Shih-Hsuan Yuan
Shih-Hsuan Yuan 2017년 1월 25일
Thanks, these look like useful resource that I can look into. For first approach, I've also tried
result_data = load(full_path);
data = result_data.data;
No major difference in speed compares to simply load(full_path).

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Steven Lord
Steven Lord 2017년 1월 25일
How many variables are in your MAT-file? How large and/or complicated are the variables NOT named data? Your first code that calls load cares about the answers to those two questions, because it needs to load ALL those variables into the workspace. I'm not certain how much (or if) the second code cares what else is in the MAT-file.
If you wanted a more apples-to-apples comparison, call load and indicate you want to read just the variable named data into memory using the variables input argument.
  댓글 수: 1
Shih-Hsuan Yuan
Shih-Hsuan Yuan 2017년 1월 25일
1 variable (Nx1 cell) in the .mat file. I have tried loading (load(path,'data')) with indication of the variable name, there's no major difference, since I'm guessing there's only 1 variable in the .mat file

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by