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 Commenti

Guillaume
Guillaume il 13 Mar 2019
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.
Guillaume
Guillaume il 13 Mar 2019
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?

Accedi per commentare.

 Risposta accettata

Steven Lord
Steven Lord il 14 Mar 2019
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 Commenti

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?
Guillaume
Guillaume il 14 Mar 2019
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.
got it... thanks!

Accedi per commentare.

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by