I want my GUI to be able to read a file, containing header info and several columns of values, and store it so that other actions can be performed on the data, Such as mean, max, RMS etc.
The 'importdata' function works great for the files I am using. I have a script that allows user to pick a file that gets imported and all the data is stored in the workspace. Works great. However, when I run this script in my GUI callback function the it workspace is internal and not global? and I cannot access the data from the file anywhere.
Is there a way to read in the data so that it can be used in other GUI callbacks?
Import data script
% Select the file
[fileName, pathName] = uigetfile('*.*','Pick Data File');
dataFile = [pathName, fileName];
%import data
allData = importdata(dataFile);
GUI callback function
function Open_File_Callback(hObject, eventdata, handles)
run ReadFile
Each function in gui has its own workspace
so you basically should share your exposed variables with other workspaces, to do so have a look at assignin
, having said that your code becomes
function Open_File_Callback(hObject, eventdata, handles)
% Select the file
[fileName, pathName] = uigetfile('*.*','Pick Data File');
dataFile = [pathName, fileName];
%import data
allData = importdata(dataFile);
%assign to base workspace
assignin('base', 'tempData', allData);
additionally you can find useful information on topic in this FAQ link