Plotting opened data in GUI

2 次查看(过去 30 天)
I am working on a GUI in Matlab. I am able to load the data pushing one button1, but I need to plot the data pushing the second button2, but an error still appers. Could you please give me a hint? This is the code below:
% --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
[filename pathname] = uigetfile('MultiSelect','on');
fullpathname = strcat(pathname, filename);
file = fullfile(pathname, filename);
text = fileread(fullpathname);
set(handles.text3,'String', fullpathname)
set(handles.text7,'String',text(:,:)) S = load(file);
% --- Executes on button press in pushbutton2. function pushbutton2_Callback(hObject, eventdata, handles) % hObject handle to pushbutton2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
S = xlsread(file);
newfilename = (S(1:end-4)); x = newfilename(:,1); y = newfilename(:,2); z = newfilename(:,2); subplot(3,1,1) plot(Vx); hold on subplot(3,1,2) plot(Vy); hold on subplot(3,1,3) plot(Vz);
I am getting this error: S = load(file); %%%%% %%%%%
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in VKG_Zobrazovac (line 42) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)VKG_Zobrazovac('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
Undefined function or variable 'file'.
Error in VKG_Zobrazovac>pushbutton2_Callback (line 111) S = xlsread(file); %%%%% %%%%%
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in VKG_Zobrazovac (line 42) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)VKG_Zobrazovac('pushbutton2_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
>>

采纳的回答

Adam
Adam 2017-2-10
编辑:Adam 2017-2-10
You need to take a read of this:
A GUI doesn't have a single workspace, each function has its own workspace, but there are various methods for sharing data between those.
handles.someData = someData;
guidata( hObject, handles )
is my favoured method, but you should familiarise yourself with the options and choose the one you prefer.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by