How can I load my .mat files from a folder into a function?
8 ビュー (過去 30 日間)
古いコメントを表示
This is my code and it calls "my_function", first file from the folder runs through the code successfully and then, error shows up.
% fetch the mat files
dirPath = '/path';
files = dir(fullfile(dirPath, '*.mat'));
% loop over the files and put them through my function
for i = 1:numFiles
fileName = files(i).name;
data = load(fullfile(dirPath, fileName));
my_function(data);
end
This is my_function which is called above.
function my_function(matfile)
%line 35
load(matfile);
This error show up when I run my code above.
Error using load
Argument must be a text scalar.
Error in my_function (line 35)
load(matfile);
0 件のコメント
回答 (1 件)
Star Strider
2023 年 4 月 22 日
The ‘data’ variable contains a structure (see struct for details) holding all the variables in the file. See the documentation section on Load List of Variables into Structure Array for details
The structure fields need to be addresed to use the data within them. Other options to do that would be struct2table or struct2cell.
0 件のコメント
参考
カテゴリ
Help Center および File 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!