How to load .asc file into an array

4 次查看(过去 30 天)
Ryan
Ryan 2012-7-25
My .asc pathway is loaded into MATLAB however the file itself isn't necessarily loading into my program. The first 30 lines are header information and then data that is about 1000x1000 with no spaces in between. It's spatial data. Ultimately I would like each spatial array to be put into a larger third dimensional array..
This is an example of what it looks like: 000000001111112222222...
Would I use textscan? This doesn't seem to work although I could be doing it wrong.. I currently have this:
Internet_pathname = strcat(recur_path,num2str(i),'/ims',num2str(i),num2str(j),'_',num2str(Res),'km.asc.gz');
ascFile= gunzip(Internet_pathname);
Fo = fopen(char(ascFile));
[a]=textscan(Fo,'%f')

回答(2 个)

Jan
Jan 2012-7-25
What do you expect as data for '000000001111112222222...'? Using '%f' treats this string as a large number. Do you want a UINT8 vector, which contains a 0 if the file contains the character '0'? Then:
value = fread(Fo, Inf, 'uchar=>uint8') - uint8('0');

Ryan
Ryan 2012-7-25
Jan- what you sent me works well... however the first 30 lines is header information I do not need, is there a way to jump over it?

Community Treasure Hunt

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

Start Hunting!

Translated by