Plotting in Matlab GUI.
이전 댓글 표시
I am working on a GUI in Matlab. I have an axes there, and two buttons. Pushing the button1 I load an Excel sheet in it (Contains 3 columns and various number of rows - always). I need to store the data in a variable, then pressing button2 I want to plot the data (I want to be able to specify which column will be plotted). I'm struggelling with passing the data insine button1 to a variable. Could you please give me a hint?
This is the code:
% --- 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');
if isequal(filename,0) || isequal(pathname,0)
return
end
guidata(hObject, handles);
fullpathname = strcat(pathname, filename);
set(handles.text3,'String', fullpathname);
fileID = fopen(strcat(pathname, filename), 'r'); % read-only permission
handles.fileData = fscanf(fileID,'%d');
handles = guidata(hObject);
handles.y = 'HERE I WANT TO STORE THE DATA.';
guidata(hObject, handles);
% --- 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)
handles = guidata(hObject);
handles.x = handles.y
guidata(hObject, handles);
plot(handles.x);
grid on
댓글 수: 6
This line looks suspicious:
handles.x = handles.y
Why would you ever want to do that at the start of your 2nd pushbutton?
Also what data exactly is it you want to store in handles.y? You already have your handles.fileData which seems to contain the data you read in.
Your question is titled 'Plotting in Matlab GUI' so I am assuming that the reading in of the data is not part of the question, otherwise it is a different question independent of plotting.
Also don't overdo the calls to
guidata( hObject, handles )
It doesn't especially do any harm apart from take time needlessly, but you only need it at the end of a callback normally, after you have set some data on the handles structure, so that this handles structure is written to the GUI in-place of the one you had at the start of the callback.
So there is no need to put this on the first line of a callback as you haven't edited the 'handles' struct at all before that.
Franta Cymorek
2017년 2월 10일
편집: Franta Cymorek
2017년 2월 10일
Adam
2017년 2월 10일
So what is handles.fileData then? If that is loaded in correctly can't you just choose your column from that?
You have access to handles.fileData in pushbutton2 callback so I still don't understand what handles.y needs to contain.
Franta Cymorek
2017년 2월 10일
편집: Franta Cymorek
2017년 2월 10일
Adam
2017년 2월 10일
Surely
col = 2;
data = handles.fileData(:,2);
is all you need if your data is loaded in correctly?
Franta Cymorek
2017년 2월 10일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!