Error can't load mat file from script, while manual loading is not an issue
2 次查看(过去 30 天)
显示 更早的评论
I've been trying to load a .mat file through a script and even used the generate script function again to see if I made any coding errors.
When I load it manually via the import data button it works fine.
However when I try to load it through a script (even matlabs own generated script) then it throws out the following error:
Error using load
Unable to read MAT-file C:\Users\vdvoor45\OneDrive -
imec\Lumerical\Pix4Life_simulations\Fluorescence_nanopore_WG_coupling\Clean_NP_in_WG_with_dipole\Mesh_convergence_tests\Output_Files_converge_X_disttoPML\WG0001_Trans_and_Purcell_mpar_1_mval_1_waterSub_x0_y0_z0_NPdia50_WL640_660.mat.
Not a binary MAT-file. Try load -ASCII to read as text.
This is matlab's generated script when manually importing this EXACT SAME FILE
function importfile(fileToRead1)
%IMPORTFILE(FILETOREAD1)
% Imports data from the specified file
% FILETOREAD1: file to read
% Auto-generated by MATLAB on 28-Mar-2019 18:01:45
% Import the file
newData1 = load('-mat', fileToRead1);
% Create new variables in the base workspace from those fields.
vars = fieldnames(newData1);
for i = 1:length(vars)
assignin('base', vars{i}, newData1.(vars{i}));
end
This script still throws the exact same error as I was having.
I also am completely sure that the file is a proper .mat file
Also if this has to do with the lenght of the name/path then please give me a workaround instead of telling me to shorten the name.
If it happens to because of length then that should be considered a bug and fixed as well in my opinion.
I have a lot of files, over a 1000 which I need to keep track of what is what and the name is part of that system.
1 个评论
Walter Roberson
2019-3-28
Visually it looks like the path might exceed 260 characters which is the Windows limit unless UNC is used.
采纳的回答
Walter Roberson
2019-3-28
编辑:Walter Roberson
2019-3-29
Maximum Path Length Limitation
In the Windows API (with some exceptions discussed in the following paragraphs), the maximum length for a path is MAX_PATH, which is defined as 260 characters. A local path is structured in the following order: drive letter, colon, backslash, name components separated by backslashes, and a terminating null character.
Your particular path is 261 characters excluding any null character (so 262 including the null).
You have reached a Windows limitation.
The Windows API has many functions that also have Unicode versions to permit an extended-length path for a maximum total path length of 32,767 characters. This type of path is composed of components separated by backslashes, each up to the value returned in the lpMaximumComponentLengthparameter of the GetVolumeInformationfunction (this value is commonly 255 characters). To specify an extended-length path, use the "\\?\" prefix. For example, "\\?\D:\very long path".
You could try that.
2 个评论
Conrado Neto
2020-1-6
I had to log in here to give you the +1
I had the same issue and your solution fixed it
thanks a lot
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!