How to load .asc file into an array

6 visualizzazioni (ultimi 30 giorni)
Ryan
Ryan il 25 Lug 2012
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')

Risposte (2)

Jan
Jan il 25 Lug 2012
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 il 25 Lug 2012
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?

Categorie

Scopri di più su Data Import and Export in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by