gpt4 book ai didi

matlab - 如何在从其他函数创建后更新 uitable?

转载 作者:太空宇宙 更新时间:2023-11-03 20:24:29 26 4
gpt4 key购买 nike

我创建了一个 matfile,其中存储了不断被用户行为覆盖的数据。这发生在函数“test()”中。

n=1
while n < 5
myVal = double(Test704(1, 780, -1)) %Returns the user's behavior
if myVal == 1
n = n + 1 %"n" is the overwritten variable in the matfile
end

save('testSave1.mat') %The matfile
m = matfile('testSave1.mat')
end

然后,我想在另一个名为“storageTest()”的函数(必须有两个独立的函数)中显示这些数据。更具体地说,storageTest() 是一个 GUI 函数,我在其中开发了一个合适的“t”。因此,我首先调用函数“test()”并将其输出值作为“t”的数据。以下是“storageTest”有趣部分的代码:

m = test()
d = [m.n]
t = uitable('Data',d, ...
'ColumnWidth',{50}, ...
'Position',[100 100 461 146]);
t.Position(3) = t.Extent(3);
t.Position(4) = t.Extent(4);

drawnow

此代码仅在“m = test()”运行结束时执行,并显示一个选项卡,我可以在其中看到“n”的最终值。但是,我希望之前显示我的表并看到我的值根据用户的行为增加。我已经在网上搜索来解决我的问题,但找不到任何答案,是否可以这样做?

最佳答案

假设我正确地解释了这个问题,如果您在调用 test 之前初始化您的表,然后将句柄传递给您的表以进行 test<,那么完成这个应该是相当简单的while 循环中更新:

例如:

function testGUI
% Initialize table
t = uitable('ColumnWidth',{50}, 'Position',[100 100 461 146]);
test(t)

function test(t)
n = 1;
while n < 5
n = n + 1;
t.Data = n;
pause(0.25); % Since we're just incrementing a number, a slight so we can actually see the change
end

当您运行上面的代码时,您会注意到表中的数据按预期迭代。

关于matlab - 如何在从其他函数创建后更新 uitable?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32145207/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com