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

In summary, to import data from a text document into Matlab, you can use the importdata function. Your data should be in a column or row format with numerical values. To create a vector using data from a text document, you can first import the data, then convert it to a row vector if needed, and assign it to a variable. You can also use data from multiple text documents to create a vector by importing each document separately and then combining the data using the vertcat function. To check if your vector was created correctly, you can use the size function to view its dimensions and the plot function to visually inspect the data points.
  • #1
da_coolest
15
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

1. How do I import data from a text document into Matlab?

To import data from a text document into Matlab, you can use the importdata function. This function will read the data from the text document and store it in a variable.

2. What format should my data be in to create a vector in Matlab?

Your data should be in a column or row format, with each element separated by a space or a comma. The data should be numerical values.

3. How do I create a vector using data from a text document?

To create a vector using data from a text document, you can first import the data using the importdata function. Then, you can use the transpose function to convert the data into a row vector if it is in a column format. Finally, you can assign the imported data to a variable to create your vector.

4. Can I use data from multiple text documents to create a vector in Matlab?

Yes, you can use data from multiple text documents to create a vector in Matlab. You can import each text document separately using the importdata function and then use the vertcat function to combine the data into a single vector.

5. How can I check if my vector was created correctly in Matlab?

To check if your vector was created correctly in Matlab, you can use the size function to view the dimensions of your vector. It should have the correct number of elements and either be a row or column vector. You can also use the plot function to visually inspect your vector and make sure it contains the correct data points.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
6K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
6K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
3K
Back
Top