필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

ascci reading fscanf help.

조회 수: 1 (최근 30일)
Coastal_Eng
Coastal_Eng 2012년 10월 19일
마감: MATLAB Answer Bot 2021년 8월 20일
Hi there, I have a ascii data file that i need to remove the first 12 rows (they contain metadata) so i do like this:
fid=fopen('madeira_3.asc')
for i=1:12;
fgetl(fid);
end
(i don't need the metadata saved so i just dump into ans)
now, i usually do a fcanf to read the rest and it works, but this time my data has decimals and is space delimited. here is how the data looks like:
" -17,313 33,371 -3971
-17,304 33,371 -3968
-17,296 33,371 -3964
-17,288 33,371 -3962
-17,279 33,371 -3959
-17,271 33,371 -3955 "
I used the code below to try to organize it in a 3 column matrix but i get stuck in the -17 when it finds the comma it stops, only if i read it as a string it works fine, but i dont want it as a string.
grid_2=fscanf(fid,'%f');
Could you please help me out. Tks in advanced. Rod.

답변 (2개)

Sean de Wolski
Sean de Wolski 2012년 10월 19일
How about just using dlmread?

Walter Roberson
Walter Roberson 2012년 10월 19일
grid_2=fscanf(fid,'%f,%f%f,%f%f,%f');
Then put the columns together, such as column1 * 1000 + sign(column1) .* column2
Alternately, read as strings, delete the commas, and parse the result as numbers.

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by