Plotting opened data in GUI
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Franta Cymorek
il 10 Feb 2017
Modificato: Franta Cymorek
il 10 Feb 2017
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 Commenti
Risposta accettata
Adam
il 10 Feb 2017
Modificato: Adam
il 10 Feb 2017
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 Commento
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!