Matlab help, fscanf (1 Viewer)

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

I have a text file with 3 columns (latitude, longitude, & station name) and 51 rows. Using fscanf I am able to read the first row of the file but not the whole file. Any ideas of how to read to the end of a text file that contains both numbers and letters?

This is what I have:

Thanks for you help,


Science Advisor
Without knowing anything about Matlab, one option is to make a loop that reads each individual line from the file until you reach the end of the file, sticking the lines together into a single string as you go.
I was able to read the file using textread.

Here is my code:
[lat,lon,sta]=textread('latlon_LAstations.txt', '%f %f %s')

Now I have another text file with / in it (ex.2000/2/5). I'm not sure how to read that. Any ideas?


Dr Transport

Science Advisor
Gold Member
if the file is in the same format, i.e. 3 columns and 51 lines, use the load function, it will read the file ito a 3 x 51 array, then break the arrays into the vectors you want, should take all of 5 lines of code to do it. Looping in Matlab is slow.....
Chileah said:
Now I have another text file with / in it (ex.2000/2/5). I'm not sure how to read that. Any ideas?
I would think that just changing the format string would work. ex:
[year month day]=textread('data.txt', '%f/%f/%f')

The Physics Forums Way

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving