Clear Filters
Clear Filters

Plotting multiple graph on 1 axes GUI

1 view (last 30 days)
Dzhamshed
Dzhamshed on 31 Jul 2012
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 Comments
Sean de Wolski
Sean de Wolski on 31 Jul 2012
So you want to plot each new set of data as an additional line on the graph?
Dzhamshed
Dzhamshed on 31 Jul 2012
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.

Sign in to comment.

Answers (1)

Sean de Wolski
Sean de Wolski on 31 Jul 2012
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.
  1 Comment
Dzhamshed
Dzhamshed on 31 Jul 2012
Can you show me on my code? Just I don't know anything about MatLAB

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!