How to update a MATLAB uitable?
16 views (last 30 days)
Show older comments
I created a matfile in which I store data that are constantly overwritten by user behavior. This occurs in a function "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
Then, I want to display these data in another function (it is essential to have two separated functions) called "storageTest()". More particularly, storageTest() is a GUI function where I developped an uitable "t". So, I first call the function "test()" and give its output values as data of "t". Here is the code of the interesting part of "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
This code executes only when "m = test()" running is over and displays me a tab in which I can see the final value of "n". However, I want my table to be displayed before and to see my value incrementing according to user's behavior. I have searched on the web to solve my issue, but I cannot find any answer, is it possible to do such a thing?
0 Comments
Answers (2)
Walter Roberson
on 22 Aug 2015
I was sure I had replied to this... perhaps my phone ate the answer again :(
If you are permitted to change the initial function, you could have it notify() a listener against a handle; that would trigger a callback.
You could run a timer function. You could run it at a modest rate and have it blindly read the file. Or you could run it at a faster rate and use dir() to check the update time on the file to see if it is worth re-reading the file.
On some operating systems, you can use operating system file or directory change notifications to be notified of a change in a file. See http://www.mathworks.com/matlabcentral/answers/9957#answer_13710 and http://www.mathworks.com/matlabcentral/answers/99277-how-do-i-programmatically-detect-a-change-in-a-directory
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!