Create a table from symbolic vectors

조회 수: 5 (최근 30일)
Farid Salazar Wong
Farid Salazar Wong 2015년 6월 26일
댓글: Seyed Morteza Raziee 2018년 6월 25일
I would like to create a table from symbolic data. I have a vector where each component is a polynomial. I would like to have a table whose entries are these polynomials. When I use table command this happens
>> syms x1 x2 x3 x4 x5 x6
>> G=[x1, x2, x3, x4, x5, x6]
G =
[ x1, x2, x3, x4, x5, x6]
>> table(G)
ans =
G
_________
[1x6 sym]
>>

답변 (4개)

Brendan Hamm
Brendan Hamm 2015년 6월 26일
The table(var1, var2,...) function will create a table where the variables are the inputs var1, var2, ...
What you want is to have a table where each element (or column) is a variable, so use array2table:
T = array2table(G)
  댓글 수: 2
Farid Salazar Wong
Farid Salazar Wong 2015년 6월 26일
It is not working for me. Now I obtain
syms x1 x2 x3 x4 x5 x6
G=[x1, x2, x3, x4, x5, x6]
G =
[ x1, x2, x3, x4, x5, x6]
>> T=array2table(G)
T =
G1 G2 G3 G4 G5 G6
_________ _________ _________ _________ _________ _________
[1x1 sym] [1x1 sym] [1x1 sym] [1x1 sym] [1x1 sym] [1x1 sym]
Brendan Hamm
Brendan Hamm 2015년 6월 26일
It is being stored that way, just not displayed that way:
>> T.G1
ans =
x1

댓글을 달려면 로그인하십시오.


Azzi Abdelmalek
Azzi Abdelmalek 2015년 6월 26일
편집: Azzi Abdelmalek 2015년 6월 26일
G=sym('x',[1,6])
H=num2cell(G)
table(H{:})
  댓글 수: 4
Farid Salazar Wong
Farid Salazar Wong 2015년 6월 26일
I would expect to have a table like this:
Var1 Var2 Var3 Var4 Var5 Var6
_________ _________ _________ _________ _________ _________
x1 x2 x3 x4 x5 x6
Walter Roberson
Walter Roberson 2015년 6월 26일
This is a limitation on the display of tables. If you need to see the content of the columns you will need to do the formatting yourself. The table is properly formed, it just isn't displaying as you hope.

댓글을 달려면 로그인하십시오.


Peter Perkins
Peter Perkins 2015년 7월 6일
Farid, tables are meant to store "column-oriented heterogeneous data". That's not what you have, or at least not in your example. You have one symbolic variable, a 1x6 row vector. There's not much point in creating a 1x6 table, it just doesn't get you anywhere that your G variable doesn't already.
What are you really trying to achieve?

Seyed Morteza Raziee
Seyed Morteza Raziee 2018년 6월 22일
편집: Walter Roberson 2018년 6월 22일
x = sym('x', [6, 2]);
y = string(x);
table(y(:,1), y(:,2), 'VariableNames', {'first_column', 'second_column'})
  댓글 수: 1
Seyed Morteza Raziee
Seyed Morteza Raziee 2018년 6월 25일
table(char(y(:,1)), char(y(:,2)), 'VariableNames', {'first_column', 'second_column'})

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Numeric Solvers에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by