Importing an ascii file in to matlab

9 views (last 30 days)
Katie
Katie on 23 Apr 2014
Answered: Kelly Kearney on 23 Apr 2014
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
Katie
Katie on 23 Apr 2014
I should say that my asc is in my folder on a hard drive and is not yet in the workspace.
Geoff Hayes
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

Sign in to comment.

Answers (4)

dpb
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

Katie
Katie on 23 Apr 2014
Thanks to you both, I'm just testing it now. It is running but obviously taking a long time!

Katie
Katie on 23 Apr 2014
OK, so it hasn't quite worked. The first time it said 'Error using dlmread (line 139) Mismatch between file and format string. Trouble reading number from file (row 1u, field 1u) ==> ncols 41679\n'
I then tried with [Z,R] = arcgridread('demtest.asc') because I am hoping to plot the DEM to be able to get the volume between that and the already drawn 3d plane.
This yielded the result 'Error using fscanf Out of memory. Type HELP MEMORY for your options.
Error in arcgridread (line 41) Z = fscanf(fid,'%g',[hdr.ncols,hdr.nrows]); '
Sorry to keep pestering, its a university project and my deadline is creeping up.
If you have any other idea about how to calculate the volume between this DEM and the plane I have drawn using cftool then I am very open to suggestions!
Katie
  1 Comment
Geoff Hayes
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

Sign in to comment.


Kelly Kearney
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.

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!