Hi.. i have 10 X 10001 matrix in .txt file. i want to make a class for each row of the matrix. how do i do that?

4 个评论

What do you call a class?
for example, 1 X 10001 i want to put it in one class. then 2 X 10001 i want to put in the 2nd class. i have 10 rows. i expect to have 10 difference class.
Again, what do you call "a class"?
It's a term that can have several meaning in matlab, none of which seem to fit what you're asking. I suggest that you give an example of input with the desired output, using valid matlab syntax
as an example, i have below matrix in my .txt.
[1, 2, 3,
4, 5, 6,
7, 8, 9]
then i want make a class on each row.
Class A = 1,2,3
Class B = 4, 5, 6
Class C = 7, 8, 9
does any way to do it?

请先登录,再进行评论。

 采纳的回答

While you can create individual variables from the rows or columns of a matrix, doing so is strongly discouraged. If your matrix was stored in the variable M use M(1, :) wherever you would have used "Class A".
If you want to refer to the rows and/or columns by name rather than by number, consider storing your data in a table.
M = [1 2 3; 4 5 6; 7 8 9];
T = array2table(M, 'RowNames', {'A', 'B','C'})
row2OfMAsTable = T('B', :) % Parentheses extracts a subtable
row2OfM = T{'B', :} % Curly braces extracts the contents of that subtable
To give your columns of M names when they are converted into variables in the table T by array2table, use 'VariableNames' instead of (or in addition to, if you want both row and variable names) 'RowNames' in the array2table call.

3 个评论

hai.. thanks for the reply. How about i have a 10X100001 matrix(see the attachment .txt file). how do i access it? by naming all of the rows A,B,C..J?
how do i access it? by naming all of the rows A,B,C..J?
By not naming the row and simply using indexing
M(1, :) to access the first row
M(999, :) to access the 999th row
So much simpler than having to figure out what name the 999th row would be.

请先登录,再进行评论。

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Tables 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by