How To Always Updating Data From Function To GUI In Matlab?
Show older comments
Hello everyone;
Nice to meet ur guys,i am new user in matlab and i currently doing some assignment by using matlab. I wish to knew how can i always update the value in the "edit text" function in Matlab Gui. Seem the value can always updating when in the matlab command window but it can't update in the GUI.Has ur guy has any idea about it?Can share it with me. Thank You and has a nice day. (^.^)
p/s:sorry for my bad English grammar.
Answers (1)
Jan
on 19 May 2012
0 votes
Updated strings and other properties are displayed after a drawnow or pause command.
14 Comments
QY Goh
on 20 May 2012
Walter Roberson
on 20 May 2012
set(handles.YourEditBox, 'String', 'This is an update');
drawnow();
QY Goh
on 20 May 2012
Walter Roberson
on 20 May 2012
What data type is x1? If it is a character string, then x1(1) would be a single character. If x1 is a numeric value, then the String you provide should be sprintf() of the value or num2str() of the value. The syntax you are using is fine, though, if x1 is a cell array of strings.
There is no big problem in making x1 a global, but you do need to declare it as global in each routine in which x1 is used. You would normally instead pass the value as a parameter to your update routine.
QY Goh
on 20 May 2012
Walter Roberson
on 20 May 2012
global x1
set(handles.Thumb, 'String', num2str(x1(1)));
drawnow();
You need to call this update routine each time you want the current value of x1 to be updated. It is not possible to have MATLAB automatically call this routine each time it detects that x1 has been changed.
QY Goh
on 21 May 2012
Image Analyst
on 21 May 2012
You know when you change x1. If you don't just search for "x1=" or "x1 =". Then, if you want to change the edit text (or a static text for that matter), just use the set() function. It is not necessary - you only need to do it when you want to update the GUI. For example, in a small loop you might not update it every loop iteration and intead just update it when the loop is done. In a loop, put a "drawnow" after it to force it to update immediately, otherwise it won't get updated right away.
QY Goh
on 21 May 2012
Walter Roberson
on 21 May 2012
Posting the code is fine.
There is no way to tell MATLAB to automatically update the GUI when your variable is set: you have to find the places that the variable is set and put in code to update the GUI.
QY Goh
on 21 May 2012
Walter Roberson
on 21 May 2012
Call the update function after x1=[0 0 0 0 0];
Call the update function after x1(count)=bc(1);
Please be aware that your statement
sort(x1,'ascend');
sorts the content of x1, and then throws away the result of the sorting. You may wish to assign the output of the sort() to something. If you assign to x1, be sure to call the update function right after you do the assignment.
QY Goh
on 21 May 2012
QY Goh
on 21 May 2012
Categories
Find more on Graphics Object Properties in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!