Converting table to matrix

9 次查看(过去 30 天)
Emilee Burris
Emilee Burris 2019-3-28
回答: dpb 2019-3-28
I have a 50x8 table that I imported from excel using readtable and now I need it into matrix form so I can plot the data a certain way
How can I convert the data to a matrix?
I have tried both these ways and it is not working
T1_selected{:,:};
A1=table2array(T1_selected);
  3 个评论
Jan
Jan 2019-3-28
"Is not working" is a lean description of the error. Please post, what you see.
Emilee Burris
Emilee Burris 2019-3-28
The error for the first one is:
Unable to concatenate the specified table variables.
Caused by:
Error using datetime/horzcat (line 1334)
All inputs must be datetimes or date/time character vectors or date/time strings.
The error for the second one is:
Error using table2array (line 27)
Unable to concatenate the specified table variables.
Caused by:
Error using datetime/horzcat (line 1334)
All inputs must be datetimes or date/time character vectors or date/time strings.

请先登录,再进行评论。

采纳的回答

dpb
dpb 2019-3-28
" from excel using readtable and now I need it into matrix form so I can plot the data a certain way "
More than likely that is not so; plot and many of its friends are datetime and table aware so you simply refer to the data out of the table you already have to plot or otherwise use it.
Even more to the point, you can't create an array out of a mix of different variable types as the error message says:
Unable to concatenate the specified table variables.
Caused by:
Error using datetime/horzcat (line 1334)
All inputs must be datetimes or date/time character vectors or date/time strings.
That's the advantage of tables; they can handle disparate data types as a group while arrays must be wholly of one class (excepting cell arrays which are useful but not needed here and would just compound the dereferencing).
As another said, we're lacking sufficient information to provide specific code, but just do something like
plot(T1.Date,T1.YourDataVarName)
where T1, YourDataVarName are the appropriate table variable name and whatever variable it is in the table you wish plotted vs time. Magic will happen...
Read the sections on tables and how to dereference them--there are a number of alternatives depending on the objectives at hand.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by