Reading Text File with Latitude, Longitude & Station Name

In summary, the conversation discusses a problem with reading a text file with 3 columns and 51 rows using fscanf in Matlab. One solution provided is to use the textread function instead. Another issue is raised regarding a text file with a different format, but it is suggested to simply change the format string to read it.
  • #1
Chileah
2
0
Hi,
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:
fid=fopen('latlon_LAstations.txt');
%station_lat=fscanf(fid,'%g',[1]);
%station_lon=fscanf(fid,'%g',[2]);
%station_name=fscanf(fid,'%s',[1]);

Thanks for you help,
Leah
 
Physics news on Phys.org
  • #2
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.
 
  • #3
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?

Thanks,
Leah
 
  • #4
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...
 
  • #5
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')
 

1. What is a text file and how is it used in reading latitude, longitude, and station name data?

A text file is a type of computer file that contains plain text data. It is commonly used to store and transfer data in a human-readable format. In the context of reading latitude, longitude, and station name data, a text file can be used to organize and store this information in a structured manner for easy retrieval and analysis.

2. How can I open and read a text file with latitude, longitude, and station name data?

To open and read a text file with this type of data, you can use a text editor program such as Notepad or Wordpad on Windows, or TextEdit on Mac. These programs allow you to view and edit the contents of a text file. You can also use programming languages, such as Python or Java, to open and read a text file and extract the desired data.

3. What is the structure of a text file containing latitude, longitude, and station name data?

The structure of a text file can vary, but it typically consists of rows and columns of data. In the case of latitude, longitude, and station name data, each row may represent a specific location, with the corresponding latitude, longitude, and station name listed in separate columns. The first row of the file may contain headers or labels for each column, and subsequent rows will contain the actual data.

4. Are there any specific file formats for storing latitude, longitude, and station name data in a text file?

There is no specific file format for storing this type of data in a text file. However, some common file formats that are used include CSV (comma-separated values), TXT (plain text), and TSV (tab-separated values). These formats allow for easy parsing and extraction of data using various programming languages.

5. Can I use latitude, longitude, and station name data from a text file in my research or analysis?

Yes, latitude, longitude, and station name data from a text file can be used in various research or analysis applications. This data can be used to plot locations on a map, analyze weather patterns, or track the movement of objects, among other things. Just make sure to properly credit the source of the data in your research.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
6K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
4K
Back
Top