Info

This question is closed. Reopen it to edit or answer.

ascci reading fscanf help.

1 view (last 30 days)
Coastal_Eng
Coastal_Eng on 19 Oct 2012
Closed: MATLAB Answer Bot on 20 Aug 2021
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.

Answers (2)

Sean de Wolski
Sean de Wolski on 19 Oct 2012
How about just using dlmread?

Walter Roberson
Walter Roberson on 19 Oct 2012
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.

Tags

Community Treasure Hunt

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

Start Hunting!