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 Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by