Converting table to matrix

조회 수: 10 (최근 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