Adding a column to a UITable and then using it.

After a few hours of trying I finally was able to add a column to a UITable
A = zeros([1 size(app.StimInputTable.Data,1)]);
app.StimInputTable.Data.Var4 = A'; % Have to make A a column vector!
for ii = 1:size(app.StimInputTable.Data,1)
app.StimInputTable.Var4(ii) = ...
app.StimInputTable.Data.Var3(ii)/app.StimInputTable.Data.Var2(ii);
But now...
assigning a value to Our new column Var4 gives me
Unrecognized method, property, or field 'Var4' for class 'matlab.ui.control.Table'.
It know what app.StimInputTable.Data.Var3(ii)/app.StimInputTable.Data.Var2(ii);
is so now put it in Var4! How hard can that be?
K>> app.StimInputTable.Data
ans =
4×4 table
Var1 Var2 Var3 Var4
____ ____ ____ ____
4 5 0 0
5 4 1 0
2 3 2 0
3 2 5 0
I can do it 1 row at a time from theCommand window:
K>> app.StimInputTable.Data
ii = 1 (etc)
K>> app.StimInputTable.Data.Var4(ii) = app.StimInputTable.Data.Var3(ii)/app.StimInputTable.Data.Var2(ii)
Although the "answer" I get is my whole
app =
MouseOdor4 with properties:
MouseOdor: [1×1 Figure]
all the properties of the whole app I won't bore you with
K>> app.StimInputTable.Data
ans =
4×4 table
Var1 Var2 Var3 Var4
____ ____ ____ _______
4 5 0 1
5 4 1 2
2 3 2 0.66667
3 2 5 2.5
Look it worked!
Next step if you don't mind anwering is to sort the table by the Var4 column

1 件のコメント

Alessandro Livi
Alessandro Livi 2024 年 7 月 21 日
BTW I tried addvars() for a while as help said to do but never got that to work following all the examples the best I could

サインインしてコメントする。

 採用された回答

Voss
Voss 2024 年 7 月 21 日
編集済み: Voss 2024 年 7 月 21 日

0 投票

app.StimInputTable.Data.Var4 = app.StimInputTable.Data.Var3./app.StimInputTable.Data.Var2;
%                 ^^^^^ you were missing the .Data

4 件のコメント

Alessandro Livi
Alessandro Livi 2024 年 7 月 22 日
Thanks I saw that after I pasted the code here. I fixed that and now it runs through that callback and then quits running in the App Designer debugger with NO errors either in the command window nor in App Designer.
My program continues to run OK but I can no longer debug.
Voss
Voss 2024 年 7 月 22 日
So no breakpoints are being triggered?
Alessandro Livi
Alessandro Livi 2024 年 7 月 22 日
Added some string stuff which completes but now when I exit the callback it halts here so maybe that is a clue?
methods (Access = protected, Sealed = true)
function newCallback = createCallbackFcn(app, callback, requiresEventData)
if nargin == 2
requiresEventData = false;
end
ams = appdesigner.internal.service.AppManagementService.instance();
newCallback = @(source, event)executeCallback(ams, ...
app, callback, requiresEventData, event);
end
Is there some magic I have to do at the end of a callback function?
Voss
Voss 2024 年 7 月 22 日
No magic required. What is the problem you are describing?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeApp Building についてさらに検索

製品

リリース

R2023b

質問済み:

2024 年 7 月 21 日

コメント済み:

2024 年 7 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by