how to convert table to matrix?
古いコメントを表示
for minimization process Boolean function by using binary decision diagram.
採用された回答
その他の回答 (4 件)
FAS
2018 年 11 月 20 日
17 投票
Suppose your table is X.
X = X{:,:}
3 件のコメント
JoshT_student
2022 年 12 月 2 日
Best answer.
Walter Roberson
2022 年 12 月 2 日
Same as the second solution that I had posted 8 months earlier...
Jacob Conrad
2023 年 3 月 15 日
dont be a jerk walter
MathWorks Support Team
2020 年 9 月 2 日
編集済み: MathWorks Support Team
2020 年 9 月 2 日
1 投票
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 件のコメント
Arsalan Aftab Sayed
2020 年 12 月 16 日
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
2020 年 12 月 16 日
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') )
Another alternative to convert table to matrix is to use a syntax: M=T.Var, e.g.
T = table(magic(5))
M=T.Var1
6 件のコメント
Walter Roberson
2021 年 8 月 4 日
This depends upon there being only a single variable in the table. That is possible, but not the most common arrangement.
Yes, it works for multiple variables as well, but it becomes painstakingly heavy for such cases, e.g.:
T = array2table(magic(5), 'VariableNames', {'Var1','Var2','Var3','Var4','Var5'})
M = [T.Var1, T.Var2, T.Var3, T.Var4, T.Var5]
Walter Roberson
2021 年 8 月 4 日
At that point, table2array() or using {:,:} indexing becomes a lot more convenient.
Sulaymon Eshkabilov
2021 年 8 月 4 日
Yes, indeed.
David Alejandro Ramirez Cajigas
2021 年 8 月 18 日
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
2021 年 8 月 18 日
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
Sulaymon Eshkabilov
2021 年 8 月 18 日
T_mat=table2array(T);
カテゴリ
ヘルプ センター および File Exchange で Data Type Conversion についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!