how to convert table to matrix?

4.226 Ansichten (letzte 30 Tage)
satya deep
satya deep am 5 Feb. 2018
Kommentiert: Jacob Conrad am 15 Mär. 2023
for minimization process Boolean function by using binary decision diagram.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 5 Feb. 2018
table2array() . Or, if the table is all numeric, you can give the table name and then {:, :} such as
mytable{:,:}
  2 Kommentare
satya deep
satya deep am 7 Feb. 2018
I want the table to matrix sir.
Walter Roberson
Walter Roberson am 7 Feb. 2018
Bearbeitet: Walter Roberson am 7 Feb. 2018
The code I posted does that. Table objects are always 2 dimensional in MATLAB and for two dimensions the terms array and matrix are the same thing.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (4)

FAS
FAS am 20 Nov. 2018
Suppose your table is X.
X = X{:,:}
  3 Kommentare
Walter Roberson
Walter Roberson am 2 Dez. 2022
Same as the second solution that I had posted 8 months earlier...
Jacob Conrad
Jacob Conrad am 15 Mär. 2023
dont be a jerk walter

Melden Sie sich an, um zu kommentieren.


MathWorks Support Team
MathWorks Support Team am 2 Sep. 2020
Bearbeitet: MathWorks Support Team am 2 Sep. 2020
To convert a table to a matrix, use the table2array function. (A matrix is a 2-D array.)
As an alternative, you can convert a table to an array by using the syntax “T{:,:}”, where “T” is the table. This syntax is the equivalent of “table2array”.
All variables in the table must have sizes and data types that allow them to be horizontally concatenated. For example, if all variables in “T” are numeric, then “table2array” returns a numeric array.
  2 Kommentare
Arsalan Aftab Sayed
Arsalan Aftab Sayed am 16 Dez. 2020
I tried both table2array and “T{:,:}” but it changes the values inside the table from 0.7 to 1. Is there a way I can keep the original values, I tried using double datatype but it doesn't work
Walter Roberson
Walter Roberson am 16 Dez. 2020
table2array() converting 0.7 to 1 could happen if the table is mixed data type including at least one integer data type such as uint8 . Please check
unique( varfun(@class, T, 'outputformat', 'cell') )

Melden Sie sich an, um zu kommentieren.


Sulaymon Eshkabilov
Sulaymon Eshkabilov am 4 Aug. 2021
Another alternative to convert table to matrix is to use a syntax: M=T.Var, e.g.
T = table(magic(5))
T = 5×1 table
Var1 __________________________ 17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9
M=T.Var1
M = 5×5
17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9
  6 Kommentare
David Alejandro Ramirez Cajigas
What can I do if I have N var, with random names, inside a table that imports from excel, this table can vary.
that is, the method of putting T. "name var" is not possible if I have N quantity of varials with N different names
Walter Roberson
Walter Roberson am 18 Aug. 2021
You can use variable indexes if the indexes are constant.
If the variable order is not constant, then you can take T.Properties.VariableNames and extract whatever subset of those you want and sort them in whatever you want. Then you can loop doing dynamic field names.
Example, selecting variables that start with "run"
names = T.Properties.VariableNames;
runvars = sort(names(startsWith(names, 'run')));
nrun = length(runvars);
for varidx = 1 : nrun
thisvarname = runvars{varidx};
thiscontent = T.(thisvarname);
stuff here
end

Melden Sie sich an, um zu kommentieren.


Sulaymon Eshkabilov
Sulaymon Eshkabilov am 18 Aug. 2021
T_mat=table2array(T);

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by