Effacer les filtres
Effacer les filtres

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

34 vues (au cours des 30 derniers jours)
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'});

Réponse acceptée

Voss
Voss le 6 Juil 2024 à 23:42
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 commentaires
Voss
Voss le 7 Juil 2024 à 22:38
Any of the following:
app.TrialsTable.Var3{ii+xx} = 'R';
app.TrialsTable.Var3(ii+xx) = {'R'};
app.TrialsTable{ii+xx, 3} = {'R'};
Alessandro Livi
Alessandro Livi le 10 Juil 2024 à 16:27
What works is this:
LRCat = categorical({'L';'R'}); % Categorical (array?)
app.TrialsTable.Var3(ii+xx) = LRCat(1); % set left

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by