MATLAB Answers

0

Updating variable matrix values to static boxes in GUI !

Asked by chamant swarup on 3 May 2019
Latest activity Commented on by chamant swarup on 5 May 2019
Iam completely new to GUI and programming any correction to code is appreciated !
I am trying to assign the value of variable x in another matfile named "main_file_Run" to static boxs !
For eg: varible x =[32, 7] and keeps updating and i when i press pushbutton it should run the matlab file needs to assign the values upated in x matrix i.e 32 nd 7 to two respective static boxes with tag names text3 and tex4 respectively.
function pushbutton1_Callback(hObject, eventdata, handles)
% a= get(handles.main_file_Run(variable x),'string');
% (set(handles.text3,'string'))
main_file_Run();
I know i completely missed the logic here ! I am only able to run the program by calling the matfile but have no clue what to do to update the values from the variables x to the two static boxes .Firstly how do we load the varible ? should we save it as text file then kind of load into the call back of pushbutton ?
thanks in advance!

  0 Comments

Sign in to comment.

1 Answer

Answer by Kevin Phung on 3 May 2019
Edited by Kevin Phung on 3 May 2019

make sure your function main_file_run() actually has an output, so in that function:
function x = main_file_run()
% blah blah blah
x = (some answer from calculations above)
end
then in your pushbutton callback:
function pushbutton1_Callback(hObject, eventdata, handles)
x = main_file_Run();
set(findobj(gcf,'Tag','text3'),'String',num2str(x(1)))
set(findobj(gcf,'Tag','text4'),'String',num2str(x(2)))
end
note :
  1. how the static text boxes display strings and not numerics.
  2. I'm finding the static textboxes through their given Tag properties (i hope you did mean this, and not their variable names defined in another function) in the current figure (gcf))
  3. For future reference, if you don't want to use gcf and want to look at a particular figure, you can try do do:
f = findobj(groot,'Name','FigureTitle') % returns figure handle of figure with specified name

  16 Comments

thanks i have run the simulation will have to check if the output will read into the static boxes !
will get backafter the simulation is complete !
But as soon as i hit the push button the window disappears running the matfile ! will have to see if pops up again after the simulation is complete . I just finished the simulation these errors again showed up and data still not captured into the static box .
Error using matlab.ui.control.UIControl/set
Invalid or deleted object.
Error in GRID_INTERFACE>pushbutton1_Callback (line 158)
set(handles.text3,'String',num2str(X(1)));
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in GRID_INTERFACE (line 38)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)GRID_INTERFACE('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating DestroyedObject Callback.
Somewhere some function is closing your GUI. You can use the debugger to set a breakpoint and go through your code line by line to see where your GUI is being closed.
X = main_file_Run();
handles.text3.String = num2str(X(1));
handles.text4.String = num2str(X(2));
I changed the code to this and it worked fine !!
thanks for the help people !!

Sign in to comment.