필터 지우기
필터 지우기

Plotting in Matlab GUI.

조회 수: 41 (최근 30일)
Franta Cymorek
Franta Cymorek 2017년 2월 10일
댓글: Franta Cymorek 2017년 2월 10일
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
Adam
Adam 2017년 2월 10일
Surely
col = 2;
data = handles.fileData(:,2);
is all you need if your data is loaded in correctly?
Franta Cymorek
Franta Cymorek 2017년 2월 10일
It's still not what I meant, but thanks for your help.

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

채택된 답변

Philip G
Philip G 2017년 2월 10일
Hi, the approach using guidata to store and retrieve data is correct. The general structure should be like
function dataimport_Callback(hObject, eventdata, handles)
x = 0:100;
y = -100:0;
handles.x =x;
handles.y =y;
guidata(hObject, handles) % here you store x and y in "handles"
function drawing_Callback(hObject, eventdata, handles)
plot(handles.x,handles.y)
What problem are you having exactly? With the above workflow using guidata(hObject) to retrieve data and guidata(hObject, handles) to store data in handles you should be good to go.
  댓글 수: 1
Franta Cymorek
Franta Cymorek 2017년 2월 10일
편집: Franta Cymorek 2017년 2월 10일
By pressing button2, I want to plot the data. Data are stored in an Excel sheet. I want to choose which column will be plotted. Respectivly, in handle.y store the loaded data. Later, in handle.x I want to specify which column.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by