Plotting opened data in GUI
1 回表示 (過去 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
>>
0 件のコメント
採用された回答
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 Center および File Exchange で Migrate GUIDE Apps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!