Importing an ascii file in to matlab

4 ビュー (過去 30 日間)
Katie
Katie 2014 年 4 月 23 日
回答済み: Kelly Kearney 2014 年 4 月 23 日
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 件のコメント
Katie
Katie 2014 年 4 月 23 日
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 2014 年 4 月 23 日
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

サインインしてコメントする。

回答 (4 件)

dpb
dpb 2014 年 4 月 23 日
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 2014 年 4 月 23 日
Thanks to you both, I'm just testing it now. It is running but obviously taking a long time!

Katie
Katie 2014 年 4 月 23 日
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 件のコメント
Geoff Hayes
Geoff Hayes 2014 年 4 月 23 日
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
Kelly Kearney 2014 年 4 月 23 日
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.

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by