Importing .mat files with text also
Show older comments
Hi, I'm trying to import large tables saved as a .mat file, but MATLAB won't load the file. The table is set up as a column matrix with ['str',#,#,#,#,#,#]. The str is a date file which could be converted to date, but takes a long time to do. (3.5million rows). I'm looking for a way to get this to import into matlab, but load won't work, and textscan doesn't either. Load is trying to pick it up as a ASCII file (due to the string) and textscan won't pick it up because it isn't a text file. Any suggestions?
Edit: Doing more research, could this also be related to my version of everything being 32bit rather than 64? The .mat file is only 36MB, so it didn't occur to me until I kept crashing the program doing some sidework.
11 Comments
José-Luis
on 14 Jul 2014
load will read binary .mat files, unless you pass it the -ascii flag, in which case it will read text. What does your command look like?
Have you read the documentation:
doc load
Mike Beacham
on 14 Jul 2014
Edited: Mike Beacham
on 14 Jul 2014
Star Strider
on 14 Jul 2014
Please post relevant parts of your code. Without it we can only guess.
Also, what version of MATLAB was the .mat file saved with? Do you have access to the script that saved it?
Mike Beacham
on 14 Jul 2014
José-Luis
on 14 Jul 2014
.mat can also be a "Microsoft Access Table". Are you sure you have the right files? Further sanity check: Are the files located in your current directory, or a directory that's in the path?
Mike Beacham
on 14 Jul 2014
...The files were saved by converting a CSV to .mat file through MATLAB on R2014a 64bit, then they were given to me. I'm running R2014a 32bit....
I don't have a 64-bit system to check on so can't answer whether there's a compatibility issue there or not. Official TMW support should be able to tell or the supplier of the files to check the doc for the 64-bit version for any caveats listed there or for any switches can use if known need them to be 32-bit compatible.
ADDENDUM
Are MAT-files compatible between the 32-bit and 64-bit versions of MATLAB?
MAT-files created with 32-bit versions and 64-bit versions of MATLAB are compatible with each other.
Note: With large data sets that use the -7.3 MAT-file format, it is possible for the 64-bit version of MATLAB to produce a MAT-file that is too large for the 32-bit version of MATLAB.
That implies other than the overall file size should be compatible if save was how files were actually created.
END ADDENDUM
Other than that, we're still guessing -- if can post the segment of code that did the save to create the files and the relevant information for the variables within, then could have something to go on to know what the files really are.
It would be of interest to see what
whos -file 'filename.mat'
returns and if could get it from both machines that would be even better.
Mike Beacham
on 14 Jul 2014
Edited: Mike Beacham
on 14 Jul 2014
dpb
on 14 Jul 2014
Indeed your surmise is correct. I don't have a version with the table type so can't test. I'd suggest after you read the data in if the point is to transport the data to the other machine, use
save filename txtvar numericvars
will be more compact and you can then just load the variables and create the table on the target machine.
Mike Beacham
on 14 Jul 2014
Mike Beacham
on 15 Jul 2014
Answers (0)
Categories
Find more on Text Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!