Trying to make a 2 value sz vector, get Error using tabular/horzcat All input arguments must be tables.
조회 수: 6 (최근 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'});
댓글 수: 0
채택된 답변
Voss
2024년 7월 6일
T = table([1;2;3;4],{'ok';'let''s';'see';'here'})
Given the table T above, T(1,:) is another table containing the first row of T:
T(1,:) % returns a table
and T(:,1) is another table containing the first column of T:
T(:,1) % returns a table
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
sum(T{:,1})
sz = [sum(T{:,1}) 4]
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]
because T(1,1) is a table and 4 is not.
댓글 수: 6
Voss
2024년 7월 7일
Any of the following:
app.TrialsTable.Var3{ii+xx} = 'R';
app.TrialsTable.Var3(ii+xx) = {'R'};
app.TrialsTable{ii+xx, 3} = {'R'};
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Categorical Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!