problem in loading .mat file (Error using load)
Show older comments
Hi,
I am having a trouble loading a particular mat file in Matlab.
I have close to 30 mat files that I consecutively generated using one script (script A). I am loading each of these mat file in another script (script B) for further analysis. When I try to load one particular mat file in script B, I get the error that looks something like this:
Error using load
Cannot read file C:\Users\....\Filename_SC7_... .mat.
'SC7' indicates the 7th file I am reading. All mat files that I load have the same name scheme with the value following SC changing (e.g. ...SC1....mat, ...SC2....mat) I suspected the file being corrupt and regenerated the file but I am still getting the same error message. I used script A and script B before without any troubles in the past so I am not sure why I am getting this issue now. Pretty much the only thing I changed this time is the name scheme, but I have used similar name schemes in the past as well.
Any comments will be appreciated!
9 Comments
Geoff Hayes
on 20 Jun 2019
Tae - have you copied and pasted the full error message to your question? Have you confirmed that the file does exist in the specified location?
Tae Lim
on 20 Jun 2019
Geoff Hayes
on 20 Jun 2019
Tae - and all other files load fine? With the only difference in the name being S7? Do all files have spaces in the folder to the file? i.e. ME 590 Direct Air Capture\LP Model EST Final (with 14 Techs)...I'm always wary when about spaces in file names...
Stephen23
on 21 Jun 2019
@Tae Lim: how are you generating the filenames? We do get questions from users who accidentally include some non-printable/control/invalid character when they generate a filename. Please get both of these:
- the entire output structure of dir, containing all of those filenames.
- the cell array/whatever of generated filenames that you use to import the files with.
and then please upload both of these (in a .mat file) so that we can check them.
Can you provide the SC7 file via some file-sharing website?
per isakson
on 21 Jun 2019
Tae Lim
on 21 Jun 2019
Answers (1)
per isakson
on 21 Jun 2019
On Win10, R2018b I have
- downloaded your two files from Box successfully
- dragged the 'Util_Tgt0.7_SC7_dr0.07_20181111_test2_FirstThreeSets_UNloadable.mat' from the Current Folder pane to Workspace pane. Load failed. Interactive Open also failed
>> load('Util_Tgt0.7_SC7_dr0.07_20181111_test2_FirstThreeSets_UNloadable.mat')
Error using load
Cannot read file H:\m\cssm\Util_Tgt0.7_SC7_dr0.07_20181111_test2_FirstThreeSets_UNloadable.mat.

- dragged the 'Util_Tgt0.7_SC7_dr0.07_20181111_test2_BAUonly.mat' from the Current Folder pane to Workspace pane. Load successful. Peek at Results
>> Results.BAU
ans =
struct with fields:
newbau: [14×96 double]
deadtotbau: [14×96 double]
retbau: [14×60×96 double]
rettotbau: [14×96 double]
totbau: [14×96 double]
CostNewCap_bau: [14×96 double]
CostNewFuel_bau: [14×96 double]
CostNewMaint_bau: [14×96 double]
CostRet_bau: [14×96 double]
CostOldFuel_bau: [14×96 double]
CostOldMaint_bau: [14×96 double]
newbau_cap: [14×96 double]
deadtotbau_cap: [14×96 double]
rettotbau_cap: [14×96 double]
totbau_cap: [14×96 double]
Ebau: [96×1 double]
linear_emcon_of_interest: [96×1 double]
EVcharegeEFsbau: [96×1 double]
retbyagebau: [96×60 double]
TotPrimaryEnergy_bau: [14×96 double]
CFnewPriE_Util: [14×96 double]
CFoldPriE_Util: [14×60×96 double]
oldbau: [14×60×96 double]
deadbau: [14×60×96 double]
discountrate: 0.07
totUtilcostmatbau: [96×3 double]
xbau: [81984×1 double]
>>
3 Comments
Tae Lim
on 21 Jun 2019
per isakson
on 21 Jun 2019
Edited: per isakson
on 21 Jun 2019
I've downloaded and loaded "FirstTwoSets" successfully.
>> load('Util_Tgt0.7_SC7_dr0.07_20181111_test2_FirstTwoSets.mat')
>> Results
Results =
struct with fields:
BAU: [1×1 struct]
CAY2015: [1×1 struct]
>>
>> Results.CAY2015
ans =
struct with fields:
new: [14×96 double]
deadtot: [14×96 double]
rettot: [14×96 double]
tot: [14×96 double]
CostNewCap: [14×96 double]
CostNewFuel: [14×96 double]
CostNewMaint: [14×96 double]
CostRet: [14×96 double]
CostOldFuel: [14×96 double]
CostOldMaint: [14×96 double]
new_cap: [14×96 double]
deadtot_cap: [14×96 double]
rettot_cap: [14×96 double]
tot_cap: [14×96 double]
E: [96×1 double]
Ebau: [96×1 double]
linear_emcon_of_interest: [96×1 double]
AnnEm: [14×96 double]
E_Captured: [96×1 double]
EVchargeEFs: [96×1 double]
incrUtil_costs_by_type: [96×3 double]
incrUtilcostsyearly: [96×1 double]
retbyage: [96×60 double]
TotPrimaryEnergy: [14×96 double]
CFnewPriE_Util: [14×96 double]
CFoldPriE_Util: [14×60×96 double]
old: [14×60×96 double]
dead: [14×60×96 double]
ret: [14×60×96 double]
totUtilcostmat: [96×3 double]
R: [36×27 double]
exitflag: 1
x: [81984×1 double]
E_annualReduc: 0.010505
>>
per isakson
on 21 Jun 2019
Edited: per isakson
on 22 Jun 2019
I've no good proposals, however
- In the File Exchange there are a few submissions that read mat-files with Java. See tag:"mat-file" . Maybe, one of these fails and returns a useful error message.
- Save your data to a mat-file version 7.3. See MAT-File Versions. Try to read the mat-file with HFD5. Start with h5disp - Display contents of HDF5 file
- Contact tech-support (if your license includes support)
Categories
Find more on Workspace Variables and MAT Files in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!