Plotting multiple graph on 1 axes GUI

8 次查看(过去 30 天)
Hello to everyone, I have got an *.xlsx database, which refreshes each 20 sec and add some rows of data. I need to make a GUI to make some temp-time graph, with an ability of making multiple graphs on one axes. How can I do this? I don'tknow anything about MATLab, I tried like here http://blogs.mathworks.com/videos/2007/08/13/video-series-reading-excel-data-into-matlab-with-a-gui/. But by the help of this it can plot just 1 graph, but there are N arrays of values for y-axis, and just 1 for x. Please, help me if you are able. here is the code
function varargout = mainGUI(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @mainGUI_OpeningFcn, ...
'gui_OutputFcn', @mainGUI_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
function mainGUI_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = mainGUI_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function pushbuttonLoadXLS_Callback(hObject, eventdata, handles)
handles.fileName=uigetfile('*.xls')
guidata(hObject, handles)
setPopupmenuString(handles.popupmenuX, eventdata, handles)
setPopupmenuString(handles.popupmenuY, eventdata, handles)
set (handles. popupmenuX, 'callback','mainGUI(''updateAxes'',gcbo,[],guidata(gcbo))')
set (handles. popupmenuY, 'callback','mainGUI(''updateAxes'',gcbo,[],guidata(gcbo))')
function setPopupmenuString(hObject, eventdata, handles)
fileName=handles.fileName;
[numbers,colNames]=xlsread(fileName);
set(hObject,'string',colNames);
function [x,y] = readExcelColumns (fileName, xColNum, yColNum)
a= xlsread(fileName);
x=a(:,xColNum);
y=a(:,yColNum)
function updateAxes (hObject, eventdata, handles)
xColNum = get(handles.popupmenuX, 'value');
yColNum = get(handles.popupmenuY, 'value');
fileName=handles.fileName;
[x,y] = readExcelColumns (fileName, xColNum, yColNum)
plot (handles.axes1,x,y)
function popupmenuY_Callback(hObject, eventdata, handles)
function popupmenuY_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function popupmenuX_Callback(hObject, eventdata, handles)
function popupmenuX_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
  2 个评论
Sean de Wolski
Sean de Wolski 2012-7-31
So you want to plot each new set of data as an additional line on the graph?
Dzhamshed
Dzhamshed 2012-7-31
Not new set of data, for example there are 8 columns with various temperature values. I want a possibility to choose, which columns are need for the graph, maybe is I choose 4 of them, there must be 4 resultant lines on the coordinate plane, and so on.

请先登录,再进行评论。

回答(1 个)

Sean de Wolski
Sean de Wolski 2012-7-31
Use plot() to plot four lines. Consider the following:
x = rand(8,10);
plot(x(:,[1 3 5 8])) %plot the first third fifth and eighth columns of x.

类别

Help CenterFile Exchange 中查找有关 Graphics Object Properties 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by