Plotting opened data in GUI

조회 수: 2 (최근 30일)
Franta Cymorek
Franta Cymorek 2017년 2월 10일
편집: Franta Cymorek 2017년 2월 10일
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.
  댓글 수: 1
Franta Cymorek
Franta Cymorek 2017년 2월 10일
편집: Franta Cymorek 2017년 2월 10일
Helped a little bit, thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (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