Error can't load mat file from script, while manual loading is not an issue

4 次查看(过去 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.

采纳的回答

Walter Roberson
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 个评论
Bob photonics
Bob photonics 2019-3-29
Thank you very much for the quick reply and the help, that was indeed exactly the problem and solution.
You've made me very happy, thank you :)
Conrado Neto
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 CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

标签

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by