Importing an ascii file in to matlab
4 views (last 30 days)
Show older comments
Hey all,
I am trying to import a rather hefty asc file (12GB) into Matlab (R2012a). It was originally a tif file which I had in ArcGIS as a DEM. I am trying to import it into Matlab to work out the volume between the DEM and a olane I have created using cftool.
When I used M=dlmread(demtest) it comes up with 'Undefined variable "demtest" or function "demtest.asc".'
Does any body have any ideas? I'm pretty new to matlab so English is you please :D Thanks
2 Comments
Geoff Hayes
on 23 Apr 2014
Hi Katie,
What is demtest defined to be? MATLAB is assuming that it is a local variable (I get the same "Undefined variable" error when I run the line M=dlmread(demtest)).
The function dlmread is expecting its input to be a string to the path and filename. Something like:
fileToRead = '/Users/geoff/Documents/demtest.asc';
Or whatever the full path (and name) is to the file you want to read. Just remember that the input must be a string.
Geoff
Answers (4)
dpb
on 23 Apr 2014
M=dlmread(demtest) [yields] 'Undefined variable "demtest" or function "demtest.asc".'
Because dlmread is expecting a file name but you didn't enclose the argument in quotes so Matlab thinks demtest is a variable.
Use
M=dlmread('demtest.asc');
instead
0 Comments
Katie
on 23 Apr 2014
1 Comment
Geoff Hayes
on 23 Apr 2014
Katie - is it necessary to use all of the data in your 12GB file or can you uses a subset of it instead? I'm not familiar with the arcgridread function but the online documentation says that its input is Arc ASCII Grid format so if you could make this data coarser (reduce the resolution?) you will have a smaller set of data to work with. (I don't know if that is possible though…)
Geoff
Kelly Kearney
on 23 Apr 2014
What are the dimensions of your grid? Your probably going to have to divide your grid into smaller blocks to do the calculations.
Most of the Mapping Toolbox functions, like arcgridread, don't play well with large files, since they're designed to read everything in all at once, which as you've discovered can easily exceed memory limits. But arc ascii files follow a simple format, so you should be able to read it in in pieces and perform your calculations without holding the whole file in memory.
0 Comments
See Also
Categories
Find more on Environment and Settings 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!