필터 지우기
필터 지우기

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?

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by