Error `Index exceeds the number of array elements` while loading .mat file
6 次查看(过去 30 天)
显示 更早的评论
I tried to encapsulate load function. However when I ran test_load_data.m, an error occurred:
Index exceeds the number of array elements. Index must not exceed 1.
S = load(path_file);
^^^^^^^^^^^^^^^
Error in
load_my_data(pathFileRelative);
A minimal working example is attached for reproduction.
If I comment out
load_my_data(pathFileRelative);
and add
load(pathFileRelative);
in test_load_data.m,
it works well.
0 个评论
回答(1 个)
Matt J
2025-9-23
编辑:Matt J
2025-9-23
You have created a variable named 'load' in this line,
load = 0; % 轴承的载荷(单位:马力)(可能是0、1、2、3马力)
and later also in,
load = str2double(tokens{1}{1});
This hides the load() function from Matlab within the workspace.
3 个评论
Matt J
2025-9-23
I'm glad it got sorted out, but please Accept-click the answer to indicate that the issue has been solved.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!