-
Notifications
You must be signed in to change notification settings - Fork 1
/
AutomationMinimaCount.m
48 lines (46 loc) · 1.96 KB
/
AutomationMinimaCount.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
MinimaList = []; % Empty list for sorting minima variables
parameter1 = 1; %Starting values of parameter d
parameter2 = 0.001; %Starting values of parameter j
L=10; %Starting values of parameter L for length
model = mphload('MyModel.mph');%load model
model.param.set('L0', L);
model.sol('sol1').clearSolutionData();
while (parameter1 <10.1)
model = mphload('MyModel.mph');%load model
model.sol('sol1').clearSolutionData();
model.param.set('d',parameter1); %set d value
model.param.set('j',parameter2);%set j value
model.study('std1').run; %run study
model.result('pg6').run(); %run plot of Y(X)
model.result.export('plot4').run; %export datafile
B = importdata('YofX.txt', ' '); %import data
x = B(:, 1); %separate column x
Y = B(:, 2);%separate column Y
TF = islocalmin(Y, 'MinProminence',0.99); %find local min
n = numel(Y(TF)); %count local min
plot(x,Y,x(TF),Y(TF),'r*') %plot minima for check
axis tight
title(['n=',num2str(n),' d= ',num2str(parameter1),' j= ',num2str(parameter2)])
drawnow;
op=['n=',num2str(n),' d= ',num2str(parameter1),' j= ',num2str(parameter2)];
disp(op);
if (n==0)
parameter2=parameter2+0.003;
model.sol("sol1").clearSolutionData();
elseif (n > 1)
parameter2=parameter2-0.004;
model.sol("sol1").clearSolutionData();
elseif (n==1)
d = strrep(num2str(parameter1), '.', '_');
filename = strcat('YofXMinima',d);
plot(x,Y,x(TF),Y(TF),'r*') %plot minima for check
axis tight
title(['d= ',num2str(parameter1),' j= ',num2str(parameter2)]) %create title with values
fname = 'C:\Users\UserName\Desktop\MinimaResults';
saveas(gcf,fullfile(fname, filename),'png');
MinimaList(end+1,:)=[parameter1,parameter2]; %add d and j value to list
parameter1 = parameter1 + 0.01;
parameter2 = 0.001;
model.sol("sol1").clearSolutionData();
end
end