Prev: standard deviation
Next: AIDS Code
From: Zach Modig on 28 Dec 2009 15:55 I have successfully built a program that imports data (in matlab format) using uiimport. I built it using several m-files. The program is successful, i.e. it does what it is supposed to. However, I am attempting to construct a GUI to make this program more usable (I have not used GUIDE). The GUI loads, and uiimport works as an import callback. It even loads the data to the correct workspace (which for some reason it doesn't do if you try to build the GUI using GUIDE). The Problem that I am running into is that another button is pushed to run the 'original' (working) program. However, because of the GUI structure and the callbacks, this is written as a function. One of these functions looks like this function[freq,alllevels,nchannels] = dataorganizer Gfiles = who('G*_*'); nchannels = length(Gfiles); G = zeros(1,2); frequencies = 0; for i = 1:nchannels G = eval(['G' num2str(i) '_' num2str(i)]); freq = G(:,1); alllevels(:,i) = G(:,2); end end the problem is that this function (within a button callback) can't see the base workspace that was imported using uiimport, and therefore the length of Gfiles is always 0. Is there a good way to pass the base workspace to this (and all of the other) nested functions? Should I go about designing my GUI another way? I'm fairly novice here so any input would be greatly appreciated.
From: Zach Modig on 29 Dec 2009 16:49 So I've found that I simply needed to use the evalin function to access the base workspace. However the use of this invokes another problem. Here is the updated code fuction[] = name Gfiles = evalin('base','who(''G*_*'')'); nchannels = length(Gfiles); G = zeros(1,2); frequencies = 0; for i = 1 : nchannels G = eval(['G' num2str(i) '_' num2str(i)]); freq = G(:,1); alllevels(:,i) = G(:,2); end end my problem is that the first returned G value, G1_1 is not recognized by the function. This matches the file of the imported variable up to Gn_n. If I use evalin instead of eval in the for loop I do not get this error message, however I simply have G = 0+1i_0+1i returned for every channel. Can anyone give me any suggestions how to rectify this situation? Thanks in advance for the help.
From: Zach Modig on 30 Dec 2009 08:57 After playing with this some more, I've noticed that function[freq, alllevels, nchannels] = dataorganizer does not assign any of the 3 output variables to the base workspace, regardless if I use eval or evalin. There has to be a way to get the function to recognize the base workspace and assign its outputs to it. Any suggestions?
From: Steven Lord on 4 Jan 2010 17:38 "Zach Modig" <zach.modig(a)gmail.com> wrote in message news:hhb5vo$fbl$1(a)fred.mathworks.com... >I have successfully built a program that imports data (in matlab format) >using uiimport. I built it using several m-files. The program is >successful, i.e. it does what it is supposed to. However, I am attempting >to construct a GUI to make this program more usable (I have not used >GUIDE). The GUI loads, and uiimport works as an import callback. It even >loads the data to the correct workspace (which for some reason it doesn't >do if you try to build the GUI using GUIDE). > > The Problem that I am running into is that another button is pushed to run > the 'original' (working) program. However, because of the GUI structure > and the callbacks, this is written as a function. One of these functions > looks like this > > function[freq,alllevels,nchannels] = dataorganizer > > Gfiles = who('G*_*'); > nchannels = length(Gfiles); > > G = zeros(1,2); > frequencies = 0; > > for i = 1:nchannels > G = eval(['G' num2str(i) '_' num2str(i)]); > freq = G(:,1); > alllevels(:,i) = G(:,2); > end > > end > > the problem is that this function (within a button callback) can't see the > base workspace that was imported using uiimport, and therefore the length > of Gfiles is always 0. Is there a good way to pass the base workspace to > this (and all of the other) nested functions? No. There isn't really even a _bad_ way to pass all of a workspace to another function (short of packaging everything into a struct or N input arguments to the "another function" or calling EVALIN in a big FOR loop.) > Should I go about designing my GUI another way? Yes. If you want your GUI to have access to data, store it somewhere the GUI can (easily) access. Put it in the UserData of your GUI's main figure, or store it as application data with SETAPPDATA/GETAPPDATA, or use nested functions for your callbacks. http://www.mathworks.com/access/helpdesk/help/techdoc/creating_guis/f5-998352.html Then retrieve the data in the callbacks that need it. Once you're done manipulating the data (say in the CloseRequestFcn for your GUI, just before it closes) return the (potentially modified) data back to the base workspace as the output of your GUI function. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
|
Pages: 1 Prev: standard deviation Next: AIDS Code |