forked from wangshuoleon/VoltammetrySimulator
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEC_simulator.m
812 lines (684 loc) · 31.3 KB
/
EC_simulator.m
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
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
function varargout = EC_simulator(varargin)
% EC_SIMULATOR MATLAB code for EC_simulator.fig
% EC_SIMULATOR, by itself, creates a new EC_SIMULATOR or raises the existing
% singleton*.
%
% H = EC_SIMULATOR returns the handle to a new EC_SIMULATOR or the handle to
% the existing singleton*.
%
% EC_SIMULATOR('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in EC_SIMULATOR.M with the given input arguments.
%
% EC_SIMULATOR('Property','Value',...) creates a new EC_SIMULATOR or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before EC_simulator_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to EC_simulator_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 EC_simulator
% Last Modified by GUIDE v2.5 28-Aug-2017 00:06:50
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @EC_simulator_OpeningFcn, ...
'gui_OutputFcn', @EC_simulator_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 EC_simulator is made visible.
function EC_simulator_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 EC_simulator (see VARARGIN)
load('E.mat');
axes(handles.axes1);
switch data.Ctrl.Mechanism
case 'E'
% show the E mechanism image in axes1
imshow('pics/E.jpg')
% set the title of ReactionParameters panel
set(handles.RP_panel,'Title','E Mechanism ReactionParameters');
case 'EC'
imshow('pics/EC.jpg')
set(handles.RP_panel,'Title','EC Mechanism ReactionParameters');
case 'ECE'
imshow('pics/ECE.jpg')
set(handles.RP_panel,'Title','ECE Mechanism ReactionParameters');
case 'ECatalysis'
imshow('pics/ECatalysis.jpg')
set(handles.RP_panel,'Title','ECatalysis Mechanism ReactionParameters');
end
switch data.Ctrl.Tech
case 'CV'
set(handles.EP_panel,'Title','Cyclic Voltammetry Parameters');
case 'CA'
set(handles.EP_panel,'Title','Chronoamperometry Parameters');
end
% set ReactionParameters table
fields=fieldnames(data.ReactionParameters);
TableData=cell(length(fields),2);
for i=1:length(fields)
TableData{i,1}=fields{i};
TableData{i,2}=data.ReactionParameters.(fields{i});
end
set(handles.RP_table,'data',TableData);
% set ElectricalParameters table
fields=fieldnames(data.ElectricalParameters);
TableData=cell(length(fields),2);
for i=1:length(fields)
TableData{i,1}=fields{i};
TableData{i,2}=data.ElectricalParameters.(fields{i});
end
set(handles.EP_table,'data',TableData);
% set the constants table
TableData=cell(2,3);
TableData{1,1}='Temperature';
TableData{1,2}=data.Const.Temperature;
TableData{1,3}='K';
TableData{2,1}='Diffusion Coefficient';
TableData{2,2}=data.Const.DiffusionCo;
TableData{2,3}='m^2/s';
set(handles.const_table,'data',TableData);
axes(handles.axes2);
plottime(data.t,data.i_profiles)
xlabel('Time s');
ylabel('Current Density A/m^2')
handles.data=data;
% Choose default command line output for EC_simulator
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes EC_simulator wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = EC_simulator_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 selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes2);
str=get(hObject,'String');
val=get(hObject,'Value');
switch str{val}
case 't vs i'
plottime(handles.data.t,handles.data.i_profiles);
xlabel('Time s');
ylabel('Current Density A/m^2')
case 'potential vs i'
overlap_cv(handles.data);
xlabel('Potential V');
ylabel('Current Density A/m^2')
case 't vs potential'
plottime(handles.data.t,handles.data.potential)
xlabel('Time s');
ylabel('Potential V')
end
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu1
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu 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 Untitled_1_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function open_Callback(hObject, eventdata, handles)
% hObject handle to open (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[Openfilename, Openpathname, filterindex] = uigetfile( ...
'*.mat', ...
'Select the experiment file', ...
'MultiSelect', 'off');
if Openfilename==0
else
Openfname=fullfile(Openpathname,Openfilename);
load(Openfname);
axes(handles.axes1);
switch data.Ctrl.Mechanism
case 'E'
% show the E mechanism image in axes1
imshow('pics/E.jpg')
% set the title of ReactionParameters panel
set(handles.RP_panel,'Title','E Mechanism ReactionParameters');
case 'EC'
imshow('pics/EC.jpg')
set(handles.RP_panel,'Title','EC Mechanism ReactionParameters');
case 'ECE'
imshow('pics/ECE.jpg')
set(handles.RP_panel,'Title','ECE Mechanism ReactionParameters');
case 'ECatalysis'
imshow('pics/ECatalysis.jpg')
set(handles.RP_panel,'Title','ECatalysis Mechanism ReactionParameters');
end
switch data.Ctrl.Tech
case 'CV'
set(handles.EP_panel,'Title','Cyclic Voltammetry Parameters');
case 'CA'
set(handles.EP_panel,'Title','Chronoamperometry Parameters');
end
% set ReactionParameters table
fields=fieldnames(data.ReactionParameters);
TableData=cell(length(fields),2);
for i=1:length(fields)
TableData{i,1}=fields{i};
TableData{i,2}=data.ReactionParameters.(fields{i});
end
set(handles.RP_table,'data',TableData);
% set ElectricalParameters table
fields=fieldnames(data.ElectricalParameters);
TableData=cell(length(fields),2);
for i=1:length(fields)
TableData{i,1}=fields{i};
TableData{i,2}=data.ElectricalParameters.(fields{i});
end
set(handles.EP_table,'data',TableData);
% set the constants table
TableData=cell(2,3);
TableData{1,1}='Temperature';
TableData{1,2}=data.Const.Temperature;
TableData{1,3}='K';
TableData{2,1}='Diffusion Coefficient';
TableData{2,2}=data.Const.DiffusionCo;
TableData{2,3}='m^2/s';
set(handles.const_table,'data',TableData);
switch data.Ctrl.SurfaceReaction
case 'on'
set(handles.sr_checkbox,'value',1)
case 'off'
set(handles.sr_checkbox,'value',0)
end
axes(handles.axes2);
plottime(data.t,data.i_profiles)
xlabel('Time s');
ylabel('Current Density A/m^2')
handles.data=data;
set(handles.popupmenu1,'Enable','on')
set(handles.export,'Enable','on')
guidata(hObject,handles);
end
% --------------------------------------------------------------------
function save_Callback(hObject, eventdata, handles)
% hObject handle to save (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[Savefile,Savepath] = uiputfile('*.mat','Save Experiment As');
if Savefile==0
else
Savefilename=fullfile(Savepath,Savefile);
save(Savefilename,'-struct','handles','data' );
end
% --------------------------------------------------------------------
function run_Callback(hObject, eventdata, handles)
% hObject handle to run (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
try
if strcmp(handles.data.Ctrl.SurfaceReaction,'off')
set(handles.figure1, 'pointer', 'watch')
drawnow;
% your computation
tic
[ handles.data.x,handles.data.t] = meshing(handles.data.ElectricalParameters, handles.data.Ctrl,handles.data.Const);
[ handles.data.potential ] = PotentialGeneration( handles.data.Ctrl ,handles.data.ElectricalParameters,handles.data.t);
[handles.data.solution,handles.data.i_profiles]=solver(handles.data.ReactionParameters,handles.data.ElectricalParameters,handles.data.Ctrl,handles.data.Const,handles.data.x,handles.data.t,handles.data.potential);
elapsedtime=toc;
set(handles.text1,'string',['Computation Time',num2str(elapsedtime)]);
set(handles.figure1, 'pointer', 'arrow');
axes(handles.axes2);
plottime(handles.data.t,handles.data.i_profiles)
xlabel('Time s');
ylabel('Current Density A/m^2')
set(handles.popupmenu1,'Enable','on')
set(handles.export,'Enable','on')
else
% handles.data.Const.DiffusionCo=1e12;
set(handles.figure1, 'pointer', 'watch')
drawnow;
tic
[ handles.data.x,handles.data.t] = meshing(handles.data.ElectricalParameters, handles.data.Ctrl,handles.data.Const);
[ handles.data.potential ] = PotentialGeneration( handles.data.Ctrl ,handles.data.ElectricalParameters,handles.data.t);
handles.data.x=linspace(0,1,10);
handles.data.Const.DiffusionCo=1e12;
[handles.data.solution,handles.data.i_profiles]=solver(handles.data.ReactionParameters,handles.data.ElectricalParameters,handles.data.Ctrl,handles.data.Const,handles.data.x,handles.data.t,handles.data.potential);
elapsedtime=toc;
ConstTable=get(handles.const_table,'data');
handles.data.Const.DiffusionCo=ConstTable{2,2};
set(handles.text1,'string',['Computation Time',num2str(elapsedtime)]);
set(handles.figure1, 'pointer', 'arrow');
axes(handles.axes2);
plottime(handles.data.t,handles.data.i_profiles)
xlabel('Time s');
ylabel('Current Density A/m^2')
set(handles.popupmenu1,'Enable','on')
set(handles.export,'Enable','on')
end
catch
set(handles.text1,'String','Error, the solver does not converge, please try to decrese the potential range')
end
guidata(hObject,handles);
% --- 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)
run_Callback(handles.run, eventdata, handles)
% --- Executes when entered data in editable cell(s) in RP_table.
function RP_table_CellEditCallback(hObject, eventdata, handles)
% hObject handle to RP_table (see GCBO)
% eventdata structure with the following fields (see UITABLE)
% Indices: row and column indices of the cell(s) edited
% PreviousData: previous data for the cell(s) edited
% EditData: string(s) entered by the user
% NewData: EditData or its converted form set on the Data property. Empty if Data was not changed
% Error: error string when failed to convert EditData to appropriate value for Data
% handles structure with handles and user data (see GUIDATA)
TableData=get(handles.RP_table,'data');
fields=fieldnames(handles.data.ReactionParameters);
for i=1:length(fields)
handles.data.ReactionParameters.(fields{i})=TableData{i,2};
end
set(handles.popupmenu1,'Enable','off')
set(handles.export,'Enable','off')
guidata(hObject,handles);
% --- Executes when entered data in editable cell(s) in EP_table.
function EP_table_CellEditCallback(hObject, eventdata, handles)
% hObject handle to EP_table (see GCBO)
% eventdata structure with the following fields (see UITABLE)
% Indices: row and column indices of the cell(s) edited
% PreviousData: previous data for the cell(s) edited
% EditData: string(s) entered by the user
% NewData: EditData or its converted form set on the Data property. Empty if Data was not changed
% Error: error string when failed to convert EditData to appropriate value for Data
% handles structure with handles and user data (see GUIDATA)
TableData=get(handles.EP_table,'data');
fields=fieldnames(handles.data.ElectricalParameters);
for i=1:length(fields)
handles.data.ElectricalParameters.(fields{i})=TableData{i,2};
end
[ handles.data.x,handles.data.t] = meshing(handles.data.ElectricalParameters, handles.data.Ctrl,handles.data.Const);
[ handles.data.potential ] = PotentialGeneration( handles.data.Ctrl ,handles.data.ElectricalParameters,handles.data.t);
axes(handles.axes2)
plottime(handles.data.t,handles.data.potential)
xlabel('Time s');
ylabel('Potential V')
set(handles.popupmenu1,'Enable','off')
set(handles.export,'Enable','off')
guidata(hObject,handles);
% --------------------------------------------------------------------
function Untitled_2_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function setups_Callback(hObject, eventdata, handles)
% hObject handle to setups (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.popupmenu1,'Enable','off')
set(handles.export,'Enable','off')
% --------------------------------------------------------------------
function Untitled_4_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function tech_Callback(hObject, eventdata, handles)
% hObject handle to tech (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function cv_Callback(hObject, eventdata, handles)
% hObject handle to cv (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.EP_panel,'title','Cyclic voltammetry Parameters')
CVParameters;
fields=fieldnames(CV);
TableData=cell(length(fields),2);
for i=1:length(fields)
TableData{i,1}=fields{i};
TableData{i,2}=CV.(fields{i});
end
set(handles.EP_table,'data',TableData);
handles.data.ElectricalParameters=CV;
handles.data.Ctrl.Tech='CV';
[ handles.data.x,handles.data.t] = meshing(handles.data.ElectricalParameters, handles.data.Ctrl,handles.data.Const);
[ handles.data.potential ] = PotentialGeneration( handles.data.Ctrl ,handles.data.ElectricalParameters,handles.data.t);
axes(handles.axes2)
plottime(handles.data.t,handles.data.potential)
xlabel('Time s');
ylabel('Potential V')
guidata(hObject,handles);
% --------------------------------------------------------------------
function CA_Callback(hObject, eventdata, handles)
% hObject handle to CA (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.EP_panel,'title','Chronoamperometry Parameters')
CAParameters;
fields=fieldnames(CA);
TableData=cell(length(fields),2);
for i=1:length(fields)
TableData{i,1}=fields{i};
TableData{i,2}=CA.(fields{i});
end
set(handles.EP_table,'data',TableData);
handles.data.ElectricalParameters=CA;
handles.data.Ctrl.Tech='CA';
[ handles.data.x,handles.data.t] = meshing(handles.data.ElectricalParameters, handles.data.Ctrl,handles.data.Const);
[ handles.data.potential ] = PotentialGeneration( handles.data.Ctrl ,handles.data.ElectricalParameters,handles.data.t);
axes(handles.axes2)
plottime(handles.data.t,handles.data.potential)
xlabel('Time s');
ylabel('Potential V')
guidata(hObject,handles);
% --------------------------------------------------------------------
function E_Callback(hObject, eventdata, handles)
% hObject handle to E (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes1);
imshow('pics/E.jpg');
set(handles.RP_panel,'title','E Parameters')
E_mechanism_parameters;
fields=fieldnames(E);
TableData=cell(length(fields),2);
for i=1:length(fields)
TableData{i,1}=fields{i};
TableData{i,2}=E.(fields{i});
end
set(handles.RP_table,'data',TableData);
handles.data.ReactionParameters=E;
handles.data.Ctrl.Mechanism='E';
guidata(hObject,handles);
% --------------------------------------------------------------------
function EC_Callback(hObject, eventdata, handles)
% hObject handle to EC (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes1);
imshow('pics/EC.jpg');
set(handles.RP_panel,'title','EC Parameters')
EC_mechanism_parameters;
fields=fieldnames(EC);
TableData=cell(length(fields),2);
for i=1:length(fields)
TableData{i,1}=fields{i};
TableData{i,2}=EC.(fields{i});
end
set(handles.RP_table,'data',TableData);
handles.data.ReactionParameters=EC;
handles.data.Ctrl.Mechanism='EC';
guidata(hObject,handles);
% --------------------------------------------------------------------
function ECE_Callback(hObject, eventdata, handles)
% hObject handle to ECE (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes1);
imshow('pics/ECE.jpg');
set(handles.RP_panel,'title','ECE Parameters')
ECE_parameters;
fields=fieldnames(ECE);
TableData=cell(length(fields),2);
for i=1:length(fields)
TableData{i,1}=fields{i};
TableData{i,2}=ECE.(fields{i});
end
set(handles.RP_table,'data',TableData);
handles.data.ReactionParameters=ECE;
handles.data.Ctrl.Mechanism='ECE';
guidata(hObject,handles);
% --------------------------------------------------------------------
function ECatalysis_Callback(hObject, eventdata, handles)
% hObject handle to ECatalysis (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes1);
imshow('pics/ECatalysis.jpg');
set(handles.RP_panel,'title','ECatalysis Parameters')
ECatalysis_parameters;
fields=fieldnames(ECatalysis);
TableData=cell(length(fields),2);
for i=1:length(fields)
TableData{i,1}=fields{i};
TableData{i,2}=ECatalysis.(fields{i});
end
set(handles.RP_table,'data',TableData);
handles.data.ReactionParameters=ECatalysis;
handles.data.Ctrl.Mechanism='ECatalysis';
guidata(hObject,handles);
% --------------------------------------------------------------------
function export_Callback(hObject, eventdata, handles)
% hObject handle to export (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function cp_Callback(hObject, eventdata, handles)
% hObject handle to cp (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[Savefile,Savepath] = uiputfile('*.mp4','Export the concentration profiles');
if Savefile==0
else
Savefilename=fullfile(Savepath,Savefile);
set(handles.figure1, 'pointer', 'watch')
drawnow;
[ video ] = output_avi( handles.data.i_profiles,handles.data.solution,handles.data.x,handles.data.t,handles.data.potential,handles.data);
v=VideoWriter(Savefilename,'MPEG-4');
open(v);
writeVideo(v,video);
close(v);
set(handles.figure1, 'pointer', 'arrow');
end
% --- Executes on button press in sr_checkbox.
function sr_checkbox_Callback(hObject, eventdata, handles)
% hObject handle to sr_checkbox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if (get(hObject,'Value') == get(hObject,'Max'))
handles.data.Ctrl.SurfaceReaction='on';
else
handles.data.Ctrl.SurfaceReaction='off';
end
set(handles.popupmenu1,'Enable','off')
set(handles.export,'Enable','off')
guidata(hObject,handles);
% Hint: get(hObject,'Value') returns toggle state of sr_checkbox
% --------------------------------------------------------------------
function csv_Callback(hObject, eventdata, handles)
% hObject handle to csv (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
hChildren = get(handles.axes2,'Children');
xData1 = get(hChildren(1),'XData');
yData1 = get(hChildren(1),'YData');
Data1=zeros(length(xData1),2);
Data1(:,1)=xData1;
Data1(:,2)=yData1;
[Savefile,Savepath] = uiputfile('*.csv','export to csv');
if Savefile==0
else
Savefilename=fullfile(Savepath,Savefile);
csvwrite(Savefilename,Data1);
end
% --------------------------------------------------------------------
function Untitled_5_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function select_files_Callback(hObject, eventdata, handles)
% hObject handle to select_files (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[Openfilename, Openpathname, filterindex] = uigetfile( ...
'*.csv', ...
'Select the reverse_plot data', ...
'MultiSelect', 'on');
if Openpathname==0
else
cla(handles.axes2)
axes(handles.axes2);
hold all
for i=1:length(Openfilename)
Openfname=fullfile(Openpathname,Openfilename{i});
data=csvread(Openfname);
reverse_plot(data(:,1),data(:,2))
end
legend(Openfilename)
hold off
end
% --- Executes when entered data in editable cell(s) in const_table.
function const_table_CellEditCallback(hObject, eventdata, handles)
% hObject handle to const_table (see GCBO)
% eventdata structure with the following fields (see UITABLE)
% Indices: row and column indices of the cell(s) edited
% PreviousData: previous data for the cell(s) edited
% EditData: string(s) entered by the user
% NewData: EditData or its converted form set on the Data property. Empty if Data was not changed
% Error: error string when failed to convert EditData to appropriate value for Data
% handles structure with handles and user data (see GUIDATA)
TableData=get(handles.const_table,'data');
handles.data.Const.Temperature=TableData{1,2};
handles.data.Const.DiffusionCo=TableData{2,2};
guidata(hObject,handles);
% --------------------------------------------------------------------
function analysis_Callback(hObject, eventdata, handles)
% hObject handle to analysis (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function about_Callback(hObject, eventdata, handles)
% hObject handle to about (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
about;
% --------------------------------------------------------------------
function pf_Callback(hObject, eventdata, handles)
% hObject handle to pf (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if strcmp(handles.data.Ctrl.Tech,'CV') && get(handles.popupmenu1,'value')==2 && get(handles. sr_checkbox,'value')==0
[ ip,Ep,locs ] = EC_findpeaks( handles.data.i_profiles, handles.data.t ,handles.data.potential,handles.data.ElectricalParameters);
axes(handles.axes2);
hold on
for i=1:length(ip)
plot(Ep(i),handles.data.i_profiles(locs(i)),'o')
str=['Ip= ',num2str(ip(i)),',Ep=',num2str(Ep(i))];
text(Ep(i)+.02,handles.data.i_profiles(locs(i)),strjoin(str))
end
hold off
else
set(handles.text1,'String','Peak finding not available')
end
% --------------------------------------------------------------------
function help_Callback(hObject, eventdata, handles)
% hObject handle to help (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Untitled_6_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function fitting_Callback(hObject, eventdata, handles)
% hObject handle to fitting (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function import_cv_Callback(hObject, eventdata, handles)
% hObject handle to import_cv (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[Openfilename, Openpathname, filterindex] = uigetfile( ...
'*.csv', ...
'Select the reverse_plot data', ...
'MultiSelect', 'off');
if Openpathname==0
else
handles.data.Ctrl.Fitting=1;
Openfname=fullfile(Openpathname,Openfilename);
EXdata=csvread(Openfname);
handles.data.ExperimentalData=EXdata;
axes(handles.axes2);
reverse_plot(handles.data.ExperimentalData(:,1),handles.data.ExperimentalData(:,2),'o')
guidata(hObject,handles);
end
% --------------------------------------------------------------------
function clear_axes_Callback(hObject, eventdata, handles)
% hObject handle to clear_axes (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.data.Ctrl.Fitting=0;
cla(handles.axis2)
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function figure1_CreateFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% --------------------------------------------------------------------
function monod_Callback(hObject, eventdata, handles)
% hObject handle to monod (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes1);
imshow('pics/monod.jpg');
set(handles.RP_panel,'title','Nernst Monod Parameters')
monod_parameters;
fields=fieldnames(monod);
TableData=cell(length(fields),2);
for i=1:length(fields)
TableData{i,1}=fields{i};
TableData{i,2}=monod.(fields{i});
end
set(handles.RP_table,'data',TableData);
handles.data.ReactionParameters=monod;
handles.data.Ctrl.Mechanism='monod';
guidata(hObject,handles);
% --------------------------------------------------------------------
function Untitled_7_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
dynamical_concentration;
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
keyboard