problem in loading .mat file (Error using load)

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

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: please show us the complete error message. This means all of the red text.
Also please upload that file in by clicking the paperclip button.
Thank you for your comments Geoff and Stephen! Here's the complete error message from the Matlab:
Error using load
Cannot read file C:\Users\Username\Box\ME 590 Direct Air Capture\LP Model EST Final (with 14 Techs)\Results\Util_20181111_Tgt0.6\Util_Tgt0.6_SC7_dr0.07_20181111.mat.
Error in ResultsProcessing_AllFiles (line 140)
load(filename);
I wasn't able to attach the file as it's 76 MB and compressing it didn't help reduce the size. If you think uploading the file is an important step maybe we can try some other means?
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...
Tae Lim
Tae Lim on 21 Jun 2019
Edited: Tae Lim on 21 Jun 2019
Geoff,
Yes, I have 26 other files that share the same name scheme and are located under the same folders. All other files load without problems. Of course the contents of these files vary slightly as they are the result of parameterized model runs. This is not the first time I generated these sort of result files but this is the first time I encountered this problem. It is also weird that I only have a problem with one of the files while rest of them seem totally fine. I even deleted the problematic file and regenerated it, but this didn't resolve the issue.
@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?
Stephen, please see my answers to your questions below:
how are you generating the filenames?
-> My script iteratively runs the code to generate results using for loops. Filename is generated at the beginning of the each iteration using the code below
ResultMatName = strcat('.\Results\Util_20181111_Tgt0.7\Util_Tgt',num2str(reduction_target),'_SC',num2str(run),'_dr',num2str(discountrate),'_20181111_test2.mat');
As you can see, the name of the file updates according to the values I assign to the variables. the variable 'run' updates at each iteration from 1 to 27 using for loop.
Under the folder where I save result files, I have a totall of 27 mat files whose name liik like below
  • Util_Tgt0.7_SC1_dr0.07_20181111
  • Util_Tgt0.7_SC2_dr0.07_20181111
  • ...
  • Util_Tgt0.7_SC27_dr0.07_20181111
They are all generated by running a single script that iteratively generates these 27 files. All of them open without problem except for the 7th file, whose name is 'Util_Tgt0.7_SC7_dr0.07_20181111'
As I look into the problematic file further, I noticed that the file becomes un-loadable in the middle of the script run. I was able to check the saved data in the file as I ran the script and didn't notice any error or weird things.. All data and data structure is still in the file. I just cannot load them afterwards.
Below I am sharing two version of the problematic ''Util_Tgt0.7_SC7_dr0.07_20181111.mat'. They are saved at two different points of the script run. Upon successful script run, this file will contain 37 sets of data; each set is iteratively generated. The first file contains first two sets of data and still opens. The second file contains first three sets of data and at this point becomes un-loadable. So this problem basically occurs upon or before saving the thrid set of data to the result file.
I appreciate all of your help!
per isakson, I just fixed the issue. You should be able to access the file now. Thank you for pointing this out!

Sign in to comment.

Answers (1)

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.
Capture.PNG
  • 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

per isakson, thank you for taking a look. Yes, I tried loading these files using different machines and noticed the same issue. The file that does not open basically contains additional set of data that look pretty similar to what you see under Results.BAU. The data is there but I cannot open the file.
CF) After reading your comments I noticed that I mistakenly shared with you the file that has only the first set of data (BAU), when I intended to share the file that contains first two set of data (BAU, CAY2015). I made this correction in my previous comment.
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
>>
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)

Sign in to comment.

Products

Asked:

on 19 Jun 2019

Edited:

on 22 Jun 2019

Community Treasure Hunt

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

Start Hunting!