Gui problem with workspace
6 views (last 30 days)
I have created gui (using Guide) but I faced a problem. My gui has 2 buttons at the moment - one for opening the file and reading in variables, second for making a plot. Each of the buttons reffers to separate .m file. Opening button runs .m file with the script that opens the file and reads the data to the workspace, whereas the second button (that is activated after the first button was used) refers to another .m file with plots (grapf and nmerical data in the table). The opening button seems to works, but by pressing second button I get error message. I looks like it does not see the variables that should be ploted. I know that gui is using different workspace than 'base' workspace, but I thought that untill I am within the same gui I am also within the same workspace so that the varialbes that should be used for ploting are easly accessible. Apparenly it is not the case (?). My question is, how to address to the workspace which stores the demanded variables?
Unrecognized function or variable 'freq'.
Error in CWT_ResSpec (line 8)
Error in run (line 91)
evalin('caller', strcat(script, ';'));
Error in CWT_software_gui>ResSpec_Callback (line 88)
Error in gui_mainfcn (line 95)
Error in CWT_software_gui (line 42)
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)CWT_software_gui('ResSpec_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
Rik on 5 Oct 2021
Why do you want to use evalin? Just have your functions return outputs.
Every function has its own workspace. To share data between different GUI elements you can use the guidata struct (or properties in case of AppDesigner).
For general advice and examples for how to create a GUI (and avoid using GUIDE), have look at this thread.