Trying to make a 2 value sz vector, get Error using tabular/horzcat All input arguments must be tables.

2 次查看(过去 30 天)
Seems so simple, I'm trying to set a new table size based on values in a previous table
C = sum(app.UITable2.Data(1,:));
No matter how hard I try I can't get the sum of a single column!
So I give up and do
sz = [C(1,1) 4];
Get the weird error that all inputs must be tables!
Try making sz a known vector type
make a property
sz = [4 4]
then try
app.sz = [C(1,1) 4];
Sorry for all the asks but I'm a very experienced C, C++ (and many other languages) programmer but this .m code is driving me crazy! Help give all kinds of useless details about setting Fonts etc but little about simple syntax for e.g. summing a column.
S = sum(A,1); does sum by columns (vs ,2 for by rows but no way to say just do column 1. Even though C is a 1x4 Can't seem to get the scaler C(1,1) out of it properly.
C(1,1) or C(1) works in the command line, just not in my app created by app designer.
Ultimately all I really want is to make a new table of the correct size with
app.TrialsTable = table('Size',sz,'VariableTypes',{'uint8','uint8','categorical','int16'});

采纳的回答

Voss
Voss 2024-7-6
T = table([1;2;3;4],{'ok';'let''s';'see';'here'})
T = 4x2 table
Var1 Var2 ____ _________ 1 {'ok' } 2 {'let's'} 3 {'see' } 4 {'here' }
Given the table T above, T(1,:) is another table containing the first row of T:
T(1,:) % returns a table
ans = 1x2 table
Var1 Var2 ____ ______ 1 {'ok'}
and T(:,1) is another table containing the first column of T:
T(:,1) % returns a table
ans = 4x1 table
Var1 ____ 1 2 3 4
In other words, subscripting a table using parentheses returns another table. To get the data out of a table, you can use curly brace subscripting. For example, to get the first column of table data:
T{:,1} % returns a numeric column vector, not a table
ans = 4x1
1 2 3 4
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
sum(T{:,1})
ans = 10
sz = [sum(T{:,1}) 4]
sz = 1x2
10 4
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
The "weird error that all inputs must be tables!" is due to trying to horizontally concatenate a table with a non-table, as in
[T(1,1) 4]
Error using tabular/horzcat (line 223)
All input arguments must be tables.
because T(1,1) is a table and 4 is not.
  6 个评论
Alessandro Livi
Alessandro Livi 2024-7-10
What works is this:
LRCat = categorical({'L';'R'}); % Categorical (array?)
app.TrialsTable.Var3(ii+xx) = LRCat(1); % set left

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by