MATLAB extract numbers in .txt file

  • Context: MATLAB 
  • Thread starter Thread starter member 428835
  • Start date Start date
  • Tags Tags
    File Matlab Numbers
Click For Summary

Discussion Overview

The discussion revolves around extracting numerical data from a .txt file using MATLAB. Participants share their experiences and suggestions regarding the methods for parsing the file, which contains both numbers and letters, and how to handle the specific format of the data.

Discussion Character

  • Technical explanation, Homework-related

Main Points Raised

  • One participant describes the structure of their .txt file, indicating that it contains both numbers and letters, and specifies that the first two sets of numbers represent coordinate pairs.
  • Another participant suggests using the "import data" function in MATLAB, noting that it can sometimes parse data effectively.
  • A further reply mentions that the success of the import function may depend on the version of MATLAB being used, with newer versions having improved data import capabilities. They also mention needing to manually delete certain characters in their experience.
  • A later response confirms that the suggested method worked for them, indicating a positive outcome from the advice given.

Areas of Agreement / Disagreement

Participants generally agree on the utility of the "import data" function in MATLAB, but there is no consensus on the best approach, as experiences may vary based on the version of MATLAB and the specific content of the .txt file.

Contextual Notes

Limitations include potential dependencies on MATLAB version and the specific formatting of the .txt file, which may affect the success of the data extraction process.

member 428835
Hi PF!

I have a .txt file with spaces and letters, along with numbers. It looks something like this:

12.0 42.0 21.0 32.0
ICF-8-1
23.0 24.0 46.0 600.0

Additionally, the first two sets of numbers each represent a coordinate pair. Then the first coordinate is (12,42) and the second is (21,32) and so on. Does anyone know how I can have MATLAB extract this info? I've attached the .txt file so you can see what I'm looking at.

Thanks so much!
 

Attachments

Physics news on Phys.org
joshmccraney said:
Hi PF!

I have a .txt file with spaces and letters, along with numbers. It looks something like this:

12.0 42.0 21.0 32.0
ICF-8-1
23.0 24.0 46.0 600.0

Additionally, the first two sets of numbers each represent a coordinate pair. Then the first coordinate is (12,42) and the second is (21,32) and so on. Does anyone know how I can have MATLAB extract this info? I've attached the .txt file so you can see what I'm looking at.

Thanks so much!

Did you try just using import data? It can sometimes parse things out nicely.
 
joshmccraney said:
Hi PF!

I have a .txt file with spaces and letters, along with numbers. It looks something like this:

12.0 42.0 21.0 32.0
ICF-8-1
23.0 24.0 46.0 600.0

Additionally, the first two sets of numbers each represent a coordinate pair. Then the first coordinate is (12,42) and the second is (21,32) and so on. Does anyone know how I can have MATLAB extract this info? I've attached the .txt file so you can see what I'm looking at.

Thanks so much!

Also depends on your version, newer versions have a nicer import data app. I got it to work in mine, but I had to delete the top characters manually.
 
  • Like
Likes   Reactions: member 428835
Thanks Student100! This totally worked!
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
24K
  • · Replies 4 ·
Replies
4
Views
5K
Replies
1
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 51 ·
2
Replies
51
Views
5K