Converting table to matrix

9 visualizzazioni (ultimi 30 giorni)
Emilee Burris
Emilee Burris il 28 Mar 2019
Risposto: dpb il 28 Mar 2019
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 Commenti
Jan
Jan il 28 Mar 2019
"Is not working" is a lean description of the error. Please post, what you see.
Emilee Burris
Emilee Burris il 28 Mar 2019
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.

Accedi per commentare.

Risposta accettata

dpb
dpb il 28 Mar 2019
" 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.

Più risposte (0)

Categorie

Scopri di più su Tables in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by