How to create a verctor in matlab using data recorded in a text document?

  • Context: MATLAB 
  • Thread starter Thread starter da_coolest
  • Start date Start date
  • Tags Tags
    Data Matlab Text
Click For Summary
SUMMARY

To create a vector in MATLAB from a text document containing comma-separated values, use the importdata function for efficient data import. The user initially attempted to read the file using fopen and fgetl, but encountered issues with indexing. The recommended approach with importdata allows for proper handling of delimiters and simplifies the process of creating a vector from the data.

PREREQUISITES
  • Familiarity with MATLAB programming environment
  • Understanding of file I/O operations in MATLAB
  • Knowledge of data structures, specifically vectors
  • Basic understanding of data formatting, particularly CSV (comma-separated values)
NEXT STEPS
  • Learn how to use importdata in MATLAB for importing data from text files
  • Explore MATLAB's readmatrix function for reading numerical data
  • Investigate data preprocessing techniques for handling delimiters and blank lines
  • Study MATLAB's documentation on file handling and data import functions
USEFUL FOR

This discussion is beneficial for MATLAB users, data analysts, and engineers who need to import and manipulate data from text files efficiently.

da_coolest
Messages
15
Reaction score
0
There is a text document with data separated by the "," sign.

such as 58.5698, 75.2495, 57.1548...

I want to createa vector called Y in MATLAB using these datas. there are 50 values.
i opened the file with the fopen command.
And then tried with the fgetl command. but when I use the "Y(1)" command to get the first value, it produces the number 5 instead of the 58.5698.

Thanks in advance.
 
Physics news on Phys.org

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
Replies
2
Views
3K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 5 ·
Replies
5
Views
7K
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
6K
  • · Replies 6 ·
Replies
6
Views
4K