Potting data in time consequtive sequential figures
1 view (last 30 days)
Show older comments
I am writing a gui app and where user inputs starttime, endtime and time windows for each dataset to be displayed. I would like to plot my data in time windows specified by the user, with figures plotting the points in consequtive time order, e.g for 1 h time window: fig 1 : from 00:00:00 till 01:00:00, fig 2: from 01:00:00 till 2:00.00. Also there are multiple variables and user can choose up to 5 variables to be plotted as subplots in each figure and each figure should have ''yes'' and ''no'' button. Here is my code: (text in bold is added only here)
M=str2double(answer(3,1))/24; % time interval in days from the uder input
handles.M=M;
N=datenum(End-Start) %end and start specified by the uder earlier
noofwindows=ceil(N/M) % how many figures with graphs will be displayed - Maybe it shouldn't be a ceiling function??
handles.noofwindows = noofwindows;
%% (the above is in a different callback function hence the handle)
noofwindows=handles.noofwindows
M=handles.M
Start=handles.Start;
NewData=handles.NewData;
row1=find(NewData(1:end, 1)==Start+M);
nfiles = noofwindows;
for i = 1:nfiles
% Create a new figure for the current data file
hFig = figure(i);
clf
set(hFig,'position',[20,50,1500,700])
% Plot the data
if n==5
for k= 0:noofwindows
N_sp = 5;
idx_sp = idx_sp + 1;
h(idx_sp) = subplot(N_sp,1,idx_sp);
hold on
plot(NewData((k*row1)+1 :(k+1)*row1,1),Variables((k*row1)+1 :(k+1)*M,indx(1)))
legend(char(list(1,indx(1))))
title('Data for XXX','fontsize',10)
datetick
idx_sp = idx_sp + 1;
h(idx_sp) = subplot(N_sp,1,idx_sp);
hold on
plot(NewData((k*row1)+1 :(k+1)*row1,1),Variables((k*row1)+1:(k+1)*row1,indx(2)))
legend(char(list(1,indx(2))))
datetick
idx_sp = idx_sp + 1;
h(idx_sp) = subplot(N_sp,1,idx_sp);
hold on
plot(NewData((k*row1)+1 :(k+1)*row1,1),Variables((k*row1)+1 :(k+1)*row1,indx(3)))
legend(char(list(1, indx(3))))
datetick
idx_sp = idx_sp + 1;
h(idx_sp) = subplot(N_sp,1,idx_sp);
hold on
plot(NewData((k*row1)+1 :(k+1)*row1,1),Variables((k*row1)+1 :(k+1)*row1,indx(4)))
legend(char(list(1, indx(4))))
datetick
idx_sp = idx_sp + 1;
h(idx_sp) = subplot(N_sp,1,idx_sp);
hold on
plot(NewData((k*row1)+1 :(k+1)*row1,1),Variables((k*row1)+1 :(k+1)*row1,indx(5)))
legend(char(list(1, indx(5))))
datetick
end
elseif n==4
for k= 0:noofwindows
M=handles.M
N_sp = 4;
idx_sp = idx_sp + 1;
h(idx_sp) = subplot(N_sp,1,idx_sp);
hold on
plot(NewData((k*row1)+1 :(k+1)*row1,1),Variables((k*row1)+1:(k+1)*row1,indx(1)))
legend(char(list(1, indx(1))))
title('KVB data for sand detection','fontsize',10)
datetick
idx_sp = idx_sp + 1;
h(idx_sp) = subplot(N_sp,1,idx_sp);
hold on
plot(NewData((k*row1)+1 :(k+1)*row1,1),Variables((k*row1)+1 :(k+1)*row1,indx(2)))
legend(char(list(1, indx(2))))
datetick
idx_sp = idx_sp + 1;
h(idx_sp) = subplot(N_sp,1,idx_sp);
hold on
plot(NewData((k*row1)+1 :(k+1)*row1,1),Variables((k*row1)+1 :(k+1)*row1,indx(3)))
legend(char(list(1, indx(3))))
datetick
idx_sp = idx_sp + 1;
h(idx_sp) = subplot(N_sp,1,idx_sp);
hold on
plot(NewData((k*row1)+1 :(k+1)*row1,1),Variables((k*row1)+1 :(k+1)*row1,indx(4)))
legend(char(list(1, indx(4))))
datetick
end
elseif n==3
for k= 0:noofwindows
M=handles.M
N_sp = 3;
idx_sp = idx_sp + 1;
h(idx_sp) = subplot(N_sp,1,idx_sp);
hold on
plot(NewData((k*row1)+1 :(k+1)*row1,1),Variables((k*row1)+1 :(k+1)*row1,indx(1)))
legend(char(list(1, indx(1))))
title('KVB data for sand detection','fontsize',10)
datetick
idx_sp = idx_sp + 1;
h(idx_sp) = subplot(N_sp,1,idx_sp);
hold on
plot(NewData((k*row1)+1 :(k+1)*row1,1),Variables((k*row1)+1 :(k+1)*row1,indx(2)))
legend(char(list(1, indx(2))))
datetick
idx_sp = idx_sp + 1;
h(idx_sp) = subplot(N_sp,1,idx_sp);
hold on
plot(NewData((k*row1)+1 :(k+1)*row1,1),Variables((k*row1)+1 :(k+1)*row1,indx(3)))
legend(char(list(1, indx(3))))
datetick
end
elseif n==2
for k= 0:noofwindows
M=handles.M
N_sp = 2
idx_sp = idx_sp + 1;
h(idx_sp) = subplot(N_sp,1,idx_sp);
hold on
plot(NewData((k*row1)+1 :(k+1)*row1,1),Variables((k*row1)+1 :(k+1)*row1,indx(1)))
legend(char(list(1, indx(1))))
title('KVB data for sand detection','fontsize',10)
datetick
idx_sp = idx_sp + 1;
h(idx_sp) = subplot(N_sp,1,idx_sp);
hold on
plot(NewData((k*row1)+1 :(k+1)*row1,1),Variables((k*row1)+1 :(k+1)*row1,indx(2)))
legend(char(list(1, indx(2))))
datetick
end
elseif n==1
for k= 0:noofwindows
M=handles.M
N_sp = 1
idx_sp = idx_sp + 1;
h(idx_sp) = subplot(N_sp,1,idx_sp);
hold on
plot(NewData((k*row1)+1 :(k+1)*row1,1),Variables((k*row1)+1 :(k+1)*row1,indx(1)))
legend(char(list(1, indx(1))))
title('KVB data for sand detection','fontsize',10)
datetick
end
else
close figure(i)
end
% Let the user to label the data "Yes" or "No"
GUI_LabelSandPattern(hFig);
% wait for the figure hFig to close before we run into the next iteration
waitfor(hFig);
end
At the moment my code only plots Fig 1 with data time from 00:00:00 til 01:00:00 (when user inputs start time 00:00:00 and end time 10:00:00). The arror I am getting is:
Error using subplot (line 326)
Index exceeds number of subplots.
Error in GUI_SandData_KVB1Final>pushbutton3_Callback (line 478)
h(idx_sp) = subplot(N_sp,1,idx_sp);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in GUI_SandData_KVB1Final (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)GUI_SandData_KVB1Final('pushbutton3_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
I am not sure what should I change to make the loop work properly. Thanks in advance! Any help appreciated.
0 Comments
Answers (0)
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!