Extracting multiple data in a MATLAB matrix

In summary, the conversation discusses extracting numerical data from multiple text files and storing it in a matrix with each element being an array. The matrix will have a size of 1 x 60 and the data from each text file will be stored in a separate array. The speaker also mentions the possibility of using a cell array or structure to organize the data. They also mention available functions for importing data from text files.
  • #1
1994Bhaskar
134
0
Hey everyone. I want to extract numerical data from files let's say g0001.txt to g0060.txt and store it in a matrix with each element is an array.
like this:
M=[g1() g2() g3() ...g60()]
matrix order can be 1 x 60 , i.e. to say 1 row and 60 columns and each element is an array which stores the entire data from g000n.txt. like i want data from g0001.txt in g1() and g0002.txt in g2() and so on.
Also later on i want plot each of these elements with respect to another array by accessing them each.
Each of these .txt files will have around 200 float values.
 
Physics news on Phys.org
  • #2
If you want each set of data to be an element of a larger "thing", then you should put them into a cell array or structure (I prefer the former).

For info and the available functions for importing data from text files, check out this doc page:
http://www.mathworks.com/help/matlab/text-files.html
 

1. What is the best way to extract multiple data in a MATLAB matrix?

The best way to extract multiple data in a MATLAB matrix is by using the colon operator (:). This operator allows you to specify a range of values to extract from the matrix.

2. Can I extract non-contiguous data from a MATLAB matrix?

Yes, you can extract non-contiguous data from a MATLAB matrix by using the square bracket notation and specifying the indices of the desired elements. For example, to extract elements at indices 1, 3, and 5, you would use the syntax M([1 3 5]).

3. How can I extract a specific column or row from a MATLAB matrix?

To extract a specific column, you can use the syntax M(:, column_index), where M is the name of your matrix and column_index is the index of the desired column. Similarly, to extract a specific row, you can use the syntax M(row_index, :).

4. Is it possible to extract data based on certain conditions from a MATLAB matrix?

Yes, you can extract data from a MATLAB matrix based on certain conditions by using logical indexing. This involves creating a logical array that specifies which elements of the matrix should be extracted, and then using this array as an index for the matrix.

5. How can I extract data from a specific part of a MATLAB matrix?

To extract data from a specific part of a MATLAB matrix, you can use the syntax M(start_row:end_row, start_column:end_column), where M is the name of your matrix and start_row, end_row, start_column, and end_column specify the range of rows and columns to be extracted.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
32
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
18
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Back
Top