Gui problem with workspace
5 次查看(过去 30 天)
显示 更早的评论
Hi,
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)
plot(freq,ampl,'b','LineWidth',0.5)
Error in run (line 91)
evalin('caller', strcat(script, ';'));
Error in CWT_software_gui>ResSpec_Callback (line 88)
run('CWT_ResSpec.m')
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in CWT_software_gui (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)CWT_software_gui('ResSpec_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
3 个评论
Rik
2021-10-5
Use the guidata struct. If you're using GUIDE, this will be retrieved every time a callback function is called.
Just make sure to store the data you want to be available for other calls as fields of that struct and use guidata(hObject,handles) to save your new data in that struct.
回答(1 个)
Rik
2021-10-5
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!