How do I get the table to produce the results from vectors?

30 views (last 30 days)
I am using this to generate the table: T = table(beta, gamma, Gv)
But in the command window it results as follows:
T =
beta gamma Gv
____________ ____________ ____________
[1x6 double] [1x6 double] [1x6 double]
Instead of giving the actual numbers.

Accepted Answer

Guillaume
Guillaume on 19 Feb 2015
table creates a row for each row of your matrices. Your matrices have only one row. If you want the columns of your matrices to be rows of the table, just transpose them:
T = table(beta', gamma', Gv', 'VariableNames', {'beta', 'gamma', 'Gv'})

More Answers (2)

Peter Perkins
Peter Perkins on 19 Feb 2015
Just to clarify what's going on:
Rich, your original code created a table from three 1x6 arrays. They all have the same number of rows, so table is happy with that. There's no rule that variables in a table need be column vectors (and in fact that's one reason for calling them "variables in the table" and not "columns of the table"). But when displaying the result, table basically says, "the variables in this table all have six columns, that's pretty wide, I'm going to display something more compact." The display kind of makes it look like there are cell arrays involved, and I think that's what tripped dpb up. But there aren't.
Had your variables all been two or three elements long, you would have seen the numbers:
>> beta = 1:3; gamma = 101:103; Gv = 1001:1003;
>> table(beta,gamma,Gv)
ans =
beta gamma Gv
___________ _________________ ____________________
1 2 3 101 102 103 1001 1002 1003
Again, perfectly legal, but still, you almost certainly want an Nx3 table, not a 1x3 table whose variables all have N columns.
  2 Comments
Carlos Borau
Carlos Borau on 18 Aug 2020
What if this is exactly what I want? (a 1x3 table whose variables all have N, such as x,y,z coordinates of an object centroid, area etc.).
I can see the scalars but not the arrays. I tried setting ColumnEditable to true to check whether at least I could see the content by clicking, but it didn't work :
centroid area whatever
____________ ____________ ____________
[1x3 double] 323 44
Steven Lord
Steven Lord on 18 Aug 2020
If that's what you want, go ahead and create and work with a table in this form.
The display just won't show all the data stored in the table variable.
>> t = table(1:6, 323, 44, 'VariableNames', ["centroid", "area", "whatever"])
t =
1×3 table
centroid area whatever
____________ ____ ________
[1×6 double] 323 44
But you can still retrieve the data as needed.
>> y = t.centroid
y =
1 2 3 4 5 6
Imagine if instead of centroid being a 1-by-6 variable it was a 1-by-10000 variable. Would you really want to display all ten thousand entries, requiring you to scroll many screens to see the area and whatever variables?

Sign in to comment.


dpb
dpb on 18 Feb 2015
"Use the curlies, Luke..." :)
You must dereference the cell arrays by the {}
T = table(beta{:}, gamma{:}, Gv{:})
Not sure if the table is smart enough on it's own to arrange the row vectors as columns or not; I don't have it to test. If not, add the .' transpose operator as
T = table(beta{:}.', gamma{:}.', Gv{:}.')
  1 Comment
Rich
Rich on 19 Feb 2015
Hi, I tried putting this but it now gives me an error message:
Cell contents reference from a non-cell array object.
Error in main (line 92) T = table(beta{:}, gamma{:}, Gv{:})
This is the main bulk of the code:
while gamma > 0.001
G = feval('performance4_3a',x1i,x2i);
Gv = [Gv G];
dx1i = feval('derivative_dx1',x1i,x2i);
dx1v = [dx1v dx1i];
dx2i = feval('derivative_dx2',x1i,x2i);
dx2v = [dx2v dx2i];
beta = [beta BETA];
BETA = (G -((dx1i.*sigma(1).*u1i)+(dx2i.*sigma(2).*u2i)))./(sqrt((dx1i.*sigma(1)).^2+(dx2i.*sigma(2)).^2));
alpha1i = -(dx1i.*sigma(1))./(sqrt((dx1i.*sigma(1)).^2+(dx2i.*sigma(2)).^2));
alpha1v = [alpha1v alpha1i];
alpha2i = -(dx2i.*sigma(2))./(sqrt((dx1i.*sigma(1)).^2+(dx2i.*sigma(2)).^2));
alpha2v = [alpha2v alpha2i];
x1i = x(1)+BETA.*alpha1i.*sigma(1);
x1v = [x1v x1i];
x2i = x(2)+BETA.*alpha2i*sigma(2);
x2v = [x2v x2i];
u1i = (x1i-x(1))./sigma(1);
u1v = [u1v u1i];
u2i = (x2i-x(2))./sigma(2);
u2v = [u2v u2i];
gamma = (BETA-beta)./beta;
end
T = table(beta{:}, gamma{:}, Gv{:})

Sign in to comment.

Categories

Find more on Tables in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!