-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPLANT.m
More file actions
562 lines (399 loc) · 17.2 KB
/
Copy pathPLANT.m
File metadata and controls
562 lines (399 loc) · 17.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
function varargout = PLANT(varargin)
% PLANT MATLAB code for PLANT.fig
% PLANT, by itself, creates a new PLANT or raises the existing
% singleton*.
%
% H = PLANT returns the handle to a new PLANT or the handle to
% the existing singleton*.
%
% PLANT('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in PLANT.M with the given input arguments.
%
% PLANT('Property','Value',...) creates a new PLANT or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before PLANT_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to PLANT_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help PLANT
% Last Modified by GUIDE v2.5 19-Dec-2016 17:33:44
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @PLANT_OpeningFcn, ...
'gui_OutputFcn', @PLANT_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
% End initialization code - DO NOT EDIT
% --- Executes just before PLANT is made visible.
function PLANT_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to PLANT (see VARARGIN)
% Choose default command line output for PLANT
handles.output = hObject;
handles.flag1=0; %% (new) initialize the variables Thr=30 and Nmin=3 in case the setting have not been modified;
handles.flag2=0;
handles.flag3=0;
handles.flag4=0; %load simulated (radiobox selected by default)
handles.runind=0;% to indicate that the data is already loaded. If ruind is 0 then show a warning message
handles.simind=0; %not data has been simulated. Show error mesage if this value is equal to 0
handles.alpha=0.95;
handles.Nmin=3;
handles.sigmap=0; %default value
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes PLANT wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = PLANT_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton9 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton10 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function edit4_Callback(hObject, eventdata, handles)
% hObject handle to edit4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit4 as text
% str2double(get(hObject,'String')) returns contents of edit4 as a double
% --- Executes during object creation, after setting all properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit5_Callback(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit5 as text
% str2double(get(hObject,'String')) returns contents of edit5 as a double
% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit6_Callback(hObject, eventdata, handles)
% hObject handle to edit6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit6 as text
% str2double(get(hObject,'String')) returns contents of edit6 as a double
% --- Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton12.
function pushbutton12_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton12 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in Estimate_sigma.
function Estimate_sigma_Callback(hObject, eventdata, handles)
% hObject handle to Estimate_sigma (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
rgb2=get(handles.Estimate_sigma,'BackgroundColor');
set(handles.Load,'BackgroundColor',rgb2);
if handles.runind==0
warndlg('You need to load some data!')
return
end
fg=handles.flag1;
if fg==1
Thr=handles.val1n;
n0=handles.val2n;
else
Thr=30;
n0=3;
end
XY=handles.AA;
sigP=Sigma_estimator(XY,Thr,n0);
handles.sigmap=sigP;
guidata(hObject,handles);
set(handles.Sigma_value,'String',sigP)
% --- Executes on button press in Segment_data.
function Segment_data_Callback(hObject, eventdata, handles)
% hObject handle to Segment_data (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
rgb3=get(handles.Segment_data,'BackgroundColor');
set(handles.Load,'BackgroundColor',rgb3);
if handles.runind==0
warndlg('You need to load some data!')
return
end
if handles.sigmap<=0
warndlg('You need to introduce a sigma value>0 !')
return
end
if handles.alpha<0 || handles.alpha>1
warndlg('You need to introduce a valid alpha value! (0<alpha<1)')
return
end
if handles.Nmin<3
warndlg('Nmin have to be >2!!')
return
end
XY=handles.AA;
sigP1=handles.sigmap;
prob=handles.alpha;
n0=handles.Nmin;
AA=Segm_alg(XY,n0,prob,sigP1,1);
alldata=handles.AA;
guidata(hObject,handles);
dlmwrite('reconstructed_trace.txt',alldata,'delimiter','\t')
% XY of reconstructed trace
dlmwrite('reconstructed_data.txt',AA,'delimiter','\t')
%The first two columns contain the coordinates(X,Y) of the change points
%(here X must be understood as the temporal coordinate).
%The rest of columns include the properties of each of the segments found,i.e.,
%time duration (third column), slope (fourth column) and offset (fifth column).
% --- Executes on button press in settings.
function settings_Callback(hObject, eventdata, handles)
% hObject handle to settings (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
prompt = {'Number of points to fit:','Min number of points to fit:'};
dlg_title = 'Input';
num_lines = 1;
defaultans = {'30','3'};
answer = inputdlg(prompt,dlg_title,num_lines,defaultans);
val1=str2num(answer{1});
val2=str2num(answer{2});
handles.val1n=val1;
handles.val2n=val2;
handles.flag1=1; % to indicate that the button was pressed
guidata(hObject,handles);
function Sigma_value_Callback(hObject, eventdata, handles)
% hObject handle to Sigma_value (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Sigma_value as text
% str2double(get(hObject,'String')) returns contents of Sigma_value as a double
val=get(hObject,'String');
newval=str2double(val);
handles.sigmap=newval;
guidata(hObject,handles);
function Nmin_value_Callback(hObject, eventdata, handles)
% hObject handle to Nmin_value (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Nmin_value as text
% str2double(get(hObject,'String')) returns contents of Nmin_value as a double
clear val newval
val=get(hObject,'String');
newval=str2double(val);
handles.Nmin=newval;
guidata(hObject,handles);
function alpha_value_Callback(hObject, eventdata, handles)
% hObject handle to alpha_value (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of alpha_value as text
% str2double(get(hObject,'String')) returns contents of alpha_value as a double
clear val newval
val=get(hObject,'String');
newval=str2double(val);
handles.alpha=newval;
guidata(hObject,handles);
% --- Executes on button press in checkbox1.
function checkbox1_Callback(hObject, eventdata, handles)
% hObject handle to checkbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of checkbox1
if (get(hObject,'Value') == get(hObject,'Max'))
flag=1;
else
flag=0;
end
handles.flag2=flag;
guidata(hObject,handles);
function edit7_Callback(hObject, eventdata, handles)
% hObject handle to edit7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit7 as text
% str2double(get(hObject,'String')) returns contents of edit7 as a double
% --- Executes during object creation, after setting all properties.
function edit7_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in Load.
function Load_Callback(hObject, eventdata, handles)
% hObject handle to Load (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
fg4=handles.flag4;
% guidata(hObject,handles);
% set(handles.edit7,'String',test)
if fg4==0 %load simulated (radiobox selected by default)
if handles.simind==0
warndlg('You need to simulate some data first!!')
return
end
temp=handles.Asim1;
handles.AA=temp;
handles.Asim1=[];
else %load experimental
[Filename,Path]=uigetfile({'.txt'},'Open file with X, Y coordinates');
if isequal(Filename,0)
return
else
AA0=importdata([Path Filename]);
end
handles.AA=AA0;
end
set(handles.Load,'BackgroundColor',[1 0 0]);
indrun=1;
handles.runind=indrun;% to indicate that the data is already loaded. If ruind is 0 then show a warning message
guidata(hObject,handles);
% --- Executes on button press in pushbutton13.
function pushbutton13_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton13 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in settings1.
function settings1_Callback(hObject, eventdata, handles)
% hObject handle to settings1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
prompt = {'Number of points in the trace:',...
'Standard deviation:','Min velocity:','Max velocity:',...
'Average segment duration'};
dlg_title = 'Input';
num_lines = 1;
defaultans = {'200','0.5','-0.2','0.4','20'};
answer = inputdlg(prompt,dlg_title,num_lines,defaultans);
%val1=str2double(answer{1});
val2=str2num(answer{1});
val3=str2double(answer{2});
val4=str2double(answer{3});
val5=str2double(answer{4});
val6=str2double(answer{5});
handles.dt=1;%val1;
handles.Ntot=val2;
handles.sigsim=val3;
handles.vmin=val4;
handles.vmax=val5;
handles.tau=val6;
handles.flag3=1; % to indicate that the button was pressed
guidata(hObject,handles);
% --- Executes on button press in simulated.
function simulated_Callback(hObject, eventdata, handles)
% hObject handle to simulated (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of simulated
% --- Executes on button press in experimental.
function experimental_Callback(hObject, eventdata, handles)
% hObject handle to experimental (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of experimental
% --- Executes on button press in pushbutton15.
function pushbutton15_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton15 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
rgb1=get(handles.pushbutton15,'BackgroundColor');
set(handles.Load,'BackgroundColor',rgb1);
fg3=handles.flag3;
if fg3==1
dt1=handles.dt;
Ntot1=handles.Ntot;
sigsim1=handles.sigsim;
vmin1=handles.vmin;
vmax1=handles.vmax;
tau1=handles.tau;
else
dt1=1;
Ntot1=200;
sigsim1=0.5;
vmin1=-0.2;
vmax1=0.4;
tau1=20;
end
[Asim,Adat]=generate_trace(dt1,Ntot1,sigsim1,vmin1,vmax1,tau1);
handles.Asim1=Asim;
dlmwrite('sim_trace.txt',Asim,'delimiter','\t')
dlmwrite('sim_data.txt',Adat,'delimiter','\t')
handles.simind=1;
guidata(hObject,handles);
% --- Executes when selected object is changed in uipanel4.
function uipanel4_SelectionChangeFcn(hObject, eventdata, handles)
% hObject handle to the selected object in uipanel4
% eventdata structure with the following fields (see UIBUTTONGROUP)
% EventName: string 'SelectionChanged' (read only)
% OldValue: handle of the previously selected object or empty if none was selected
% NewValue: handle of the currently selected object
% handles structure with handles and user data (see GUIDATA)
% set(handles.experimental,'Value','max');
if hObject==handles.simulated
fg4=0; %simulated trace
else
fg4=1; %experimental trace
end
handles.flag4=fg4;
guidata(hObject,handles);
% --- Executes on button press in pushbutton16.
function pushbutton16_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton16 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
msgbox('PLANT. SOFTWARE VERSION 1.2. A.Sosa-Costa & C. Manzo, March. 2017' )