/normxcorr/trunk

To get this branch, use:
bzr branch http://suren.me/webbzr/normxcorr/trunk

« back to all changes in this revision

Viewing changes to displacement.m

  • Committer: Suren A. Chilingaryan
  • Date: 2009-01-15 13:50:29 UTC
  • Revision ID: csa@dside.dyndns.org-20090115135029-wleapicg9a4593tp
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
% Initialize data
 
3
% written by Chris and Dan
 
4
 
 
5
% Displacement.m allows you to analyze the data you aquiered with the
 
6
% correlation, fitting or mean routine. It only needs the validx and
 
7
% validy and can calculate strain from it. Before you start you should 
 
8
% consider cleaning up the data as described in the guide. After that step
 
9
% you can analyze parts of your data, or the full set. Try to use also the
 
10
% console command, e.g. if you want to analyze only image 100-110 since
 
11
% something really interesting happend there, load validx and validy into
 
12
% your workspace and call
 
13
% displacement(validx(:,100:110),validy(:,100:110));
 
14
% In this case displacement only loads the important images and you can
 
15
% clean this part of your data set.
 
16
 
 
17
% Changed 3. February 2008
 
18
 
 
19
 
 
20
function [validx,validy]=displacement(validx,validy);
 
21
 
 
22
%load data in case you did not load it into workspace yet
 
23
if exist('validx')==0
 
24
    [validxname,Pathvalidx] = uigetfile('*.dat','Open validx.dat');
 
25
    if validxname==0
 
26
        disp('You did not select a file!')
 
27
        return
 
28
    end
 
29
    cd(Pathvalidx);
 
30
    validx=importdata(validxname,'\t');
 
31
end
 
32
if exist('validy')==0
 
33
    [validyname,Pathvalidy] = uigetfile('*.dat','Open validy.dat');
 
34
    if validyname==0
 
35
        disp('You did not select a file!')
 
36
        return
 
37
    end
 
38
    cd(Pathvalidy);
 
39
    validy=importdata(validyname,'\t');
 
40
end
 
41
 
 
42
%define the size of the data set
 
43
sizevalidx=size(validx);
 
44
sizevalidy=size(validy);
 
45
looppoints=sizevalidx(1,1);
 
46
loopimages=sizevalidx(1,2);
 
47
 
 
48
%calculate the displacement relative to the first image in x and y
 
49
%direction
 
50
clear displx;
 
51
validxfirst=zeros(size(validx));
 
52
validxfirst=mean(validx(:,1),2)*ones(1,sizevalidx(1,2));
 
53
displx=validx-validxfirst;
 
54
clear validxfirst
 
55
clear disply;
 
56
validyfirst=zeros(size(validy));
 
57
validyfirst=mean(validy(:,1),2)*ones(1,sizevalidy(1,2));
 
58
disply=validy-validyfirst;
 
59
clear validyfirst
 
60
 
 
61
%Prompt user for type of plotting / visualization
 
62
selection10 = menu(sprintf('How do you want to visualize your data?'),'3D Mesh Plot of Displacement'...
 
63
    ,'Full Strain Plots','Strain Measurement between 2 Points','1D Average Strain Measurement',...
 
64
    'Rotate Orientation (exchange x and y)','Remove badly tracked marker, one by one (Position)',...
 
65
    'Delete multible markers (Position)','Delete markers from displacement vs. position plot',...
 
66
    'Delete points moving relative to their neighbours','Select Markers to Analyze ',...
 
67
    'Save validx and validy','Average a couple of images','Cancel');
 
68
 
 
69
% Selection for Cancel - All windows will be closed and you jump back to
 
70
% the command line
 
71
if selection10==13
 
72
    close all;
 
73
    return
 
74
end
 
75
 
 
76
% This selection will average up a specified number of images to reduce the
 
77
% noise of the data set. I would like to point out that you will need to
 
78
% average your other sensor data (e.g. load data), too, to match it to your
 
79
% strain data.
 
80
if selection10==12
 
81
    prompt = {'How many images would you like to combine as a base image?'};
 
82
    dlg_title = 'Input number of images:';
 
83
    num_lines= 1;
 
84
    def     = {'5'};
 
85
    answer = inputdlg(prompt,dlg_title,num_lines,def);
 
86
    if str2num(cell2mat(answer(1)))==0
 
87
        disp('Get out, you changed your mind?')
 
88
        [validx validy]=displacement(validx,validy);
 
89
        return
 
90
    else
 
91
        baseimages = str2num(cell2mat(answer(1)));
 
92
        if baseimages==[]
 
93
            disp('Give me a number, will you?')
 
94
            [validx validy]=displacement(validx,validy);
 
95
            return
 
96
        end
 
97
        if baseimages>loopimages
 
98
            disp('That is too large?!')
 
99
        else
 
100
            baseimagemean=mean(validx(:,1:baseimages),2);
 
101
            validx(:,1:baseimages-1)=[];
 
102
            validx(:,1)=baseimagemean;
 
103
            baseimagemean=mean(validy(:,1:baseimages),2);
 
104
            validy(:,1:baseimages-1)=[];
 
105
            validy(:,1)=baseimagemean;
 
106
        end
 
107
    end
 
108
    [validx validy]=displacement(validx,validy);
 
109
    return
 
110
end
 
111
 
 
112
% Save validx and validy, very useful if you cleaned up your dataset. Data
 
113
% will be saved as -ascii text file. If you send data like this by email
 
114
% you can reduce the size tremendously by compressing it. Use ZIP or RAR.
 
115
if selection10==11
 
116
    [FileName,PathName] = uiputfile('validx_corr.dat','Save validx');
 
117
    if FileName==0
 
118
        disp('You did not save your file!')
 
119
        [validx validy]=displacement(validx,validy);
 
120
        return
 
121
    else
 
122
        cd(PathName)
 
123
        save(FileName,'validx','-ascii')
 
124
        [FileName,PathName] = uiputfile('validy_corr.dat','Save validy');
 
125
        if FileName==0
 
126
            disp('You did not save your file!')
 
127
            [validx validy]=displacement(validx,validy);
 
128
        else
 
129
            cd(PathName)
 
130
            save(FileName,'validy','-ascii')
 
131
        end
 
132
        [validx validy]=displacement(validx,validy);
 
133
        return
 
134
    end
 
135
end
 
136
 
 
137
% Select Points from detailed Analysis
 
138
if selection10==10
 
139
    [validx validy validxbackup validybackup]=ppselection_func(validx,validy);
 
140
    if validx==0
 
141
        validx=validxbackup;
 
142
        validy=validybackup;
 
143
    end
 
144
    if validy==0
 
145
        validx=validxbackup;
 
146
        validy=validybackup;
 
147
    end
 
148
    [validx validy]=displacement(validx,validy);
 
149
end
 
150
 
 
151
% Remove markers moving relativ to their neighbours
 
152
if selection10==9
 
153
    [validx,validy,displx,disply]=delete_jumpers(validx,validy,displx,disply);
 
154
    [validx validy]=displacement(validx,validy);
 
155
end
 
156
 
 
157
% Remove markers from the displacement vs. position plot
 
158
if selection10==8
 
159
    [validx,validy,displx,disply]=removepoints_func(validx,validy,displx,disply);
 
160
    [validx validy]=displacement(validx,validy);
 
161
end
 
162
 
 
163
% Remove bad points
 
164
if selection10==7
 
165
    [validx,validy]=removepoints_func2(validx,validy);
 
166
    [validx validy]=displacement(validx,validy);
 
167
end
 
168
 
 
169
% Remove bad points
 
170
if selection10==6
 
171
    [validx validy]=removepoints_func3(validx,validy);
 
172
    [validx validy]=displacement(validx,validy);
 
173
end
 
174
 
 
175
% Rotate Matrix
 
176
if selection10==5
 
177
    [validx, validy]=rotatematrix(validx,validy);
 
178
    [validx validy]=displacement(validx,validy);
 
179
end
 
180
 
 
181
% 1D Strain plot using average strains for ELASTIC STRAIN only
 
182
if selection10==4
 
183
    [validx validy]=strain_1D_average_func(validx, validy,displx,disply);
 
184
    [validx validy]=displacement(validx,validy);
 
185
end
 
186
 
 
187
% 1D Strain plot
 
188
if selection10==3
 
189
    [validx, validy,displx,disply]=strain_1D_2Points_func(validx, validy,displx,disply);
 
190
    [validx validy]=displacement(validx,validy);
 
191
end
 
192
 
 
193
% Fast plotting, cropping needed for polynomial fit
 
194
if selection10==2
 
195
    [validx, validy,displx,disply]=polyfit3D(validx, validy,displx,disply);
 
196
    [validx validy]=displacement(validx,validy);
 
197
end
 
198
 
 
199
% 3D Mesh Plotting
 
200
if selection10==1
 
201
    if sizevalidx(1,1)>2
 
202
    [validx, validy,displx,disply]=meshplot(validx,validy,displx,disply);
 
203
    else
 
204
        disp('You need at least three markers to display the 3D-plot')
 
205
        msgbox('You need at least three markers to display the 3D-plot','3D-Plot','warn');
 
206
    end
 
207
    [validx validy]=displacement(validx,validy);
 
208
end
 
209
 
 
210
%---------------------------------
 
211
 
 
212
function [validx,validy,displx,disply]=delete_jumpers(validx,validy,displx,disply);
 
213
 
 
214
% written by Chris
 
215
 
 
216
% This is a filter which helps to find jumpy data points which are 
 
217
% oscillating or stop moving.
 
218
% The Filter starts by finding the next 10 datapoint neighbours 
 
219
% (num_neighbours), calculates their mean position and then plots the
 
220
% difference between each data point and its neighbours versus image
 
221
% number. If a data point is jumping around it will show up as a spike. But
 
222
% be careful, one bad one will also affect his neighbours, therefore its
 
223
% worthwhile to use this filter step by step.
 
224
 
 
225
% Changed 3. February 2008
 
226
 
 
227
num_neighbours=10;
 
228
 
 
229
doitonemoretime=1
 
230
 
 
231
while doitonemoretime==1
 
232
    % defining variables
 
233
    sizevalidx=size(validx);
 
234
    sizevalidy=size(validy);
 
235
    looppoints=sizevalidx(1,1);
 
236
    loopimages=sizevalidx(1,2);
 
237
 
 
238
    % clear the used ones
 
239
    clear validxtemp
 
240
    clear validytemp
 
241
    clear meandistancetemp
 
242
    clear sizevalidxtemp
 
243
    clear sizevalidytemp
 
244
    clear looppointstemp
 
245
    clear loopimagestemp
 
246
    clear max_distance
 
247
    clear min_distance
 
248
    clear dist_matrix
 
249
    clear dist_sort
 
250
    clear dist_index
 
251
    clear meandistance
 
252
    tic
 
253
    % calculate the distance to the next data points
 
254
%     dist_matrix=zeros(looppoints,looppoints);
 
255
    meandistance=zeros(sizevalidx);
 
256
    
 
257
    g=waitbar(0,'Processing the markers...');
 
258
    for i=1:looppoints
 
259
        waitbar(i/looppoints);
 
260
        dist_matrix=(((validx(:,1)-validx(i,1)).^2+(validy(:,1)-validy(i,1)).^2).^(0.5))';
 
261
        %   end
 
262
 
 
263
        % find the next neighbours by indexing the ones closest
 
264
        [dist_sort, dist_index]=sort(dist_matrix);
 
265
 
 
266
        % take the mean position of the closest data points of each for all
 
267
        % images
 
268
        meandistance(i,:)= validx(i,:)-mean(validx(dist_index(2:num_neighbours),:),1);
 
269
        max_distance(i)= max(diff(meandistance(i,:)-meandistance(i,1)));
 
270
        min_distance(i)= min(diff(meandistance(i,:)-meandistance(i,1)));
 
271
    end
 
272
    close(g)
 
273
toc
 
274
    for i=1:looppoints
 
275
        plot(diff(meandistance(i,:)-meandistance(i,1)))
 
276
        hold on
 
277
    end
 
278
   toc     
 
279
    % Select an upper and lower boundary
 
280
    xlabel('Image number[ ]')
 
281
    ylabel('Relative marker dispacement [Pixels]')
 
282
    title(sprintf('Define the upper and lower bound by clicking above and below the valid points'))
 
283
    marker_pt=(ginput(1));
 
284
    x_mark(1,1) = marker_pt(1);
 
285
    y_mark(1,1) = marker_pt(2);
 
286
    plot([1;loopimages],[y_mark(1,1);y_mark(1,1)],'r');
 
287
 
 
288
    title(sprintf('Define the upper and lower bound by clicking above and below the valid points'))
 
289
    marker_pt=(ginput(1));
 
290
    x_mark(1,2) = marker_pt(1);
 
291
    y_mark(1,2) = marker_pt(2);
 
292
    plot([1;loopimages],[y_mark(1,2);y_mark(1,2)],'r');
 
293
 
 
294
    upperbound=max(y_mark);
 
295
    lowerbound=min(y_mark);
 
296
 
 
297
    hold off
 
298
    
 
299
    validxtemp=validx;
 
300
    validytemp=validy;
 
301
    meandistancetemp=meandistance;
 
302
    
 
303
    
 
304
    validxtemp(find(max_distance>upperbound | min_distance<lowerbound),:)=[];
 
305
    validytemp(find(max_distance>upperbound | min_distance<lowerbound),:)=[];
 
306
    meandistancetemp(find(max_distance>upperbound |min_distance<lowerbound),:)=[];
 
307
    sizevalidxtemp=size(validxtemp);
 
308
    sizevalidytemp=size(validytemp);
 
309
    looppointstemp=sizevalidxtemp(1,1);
 
310
    loopimagestemp=sizevalidxtemp(1,2);
 
311
    
 
312
    for i=1:looppointstemp
 
313
        plot(diff(meandistancetemp(i,:)-meandistancetemp(i,1)))
 
314
        hold on
 
315
    end
 
316
    plot([1;loopimages],[y_mark(1,1);y_mark(1,1)],'r');
 
317
    plot([1;loopimages],[y_mark(1,2);y_mark(1,2)],'r');
 
318
    
 
319
    hold off
 
320
 
 
321
    selection_filter = menu('Do you like the result?','Take it as is','Want to select more','Try again','Cancel');
 
322
    if selection_filter==1
 
323
        validx=validxtemp;
 
324
        validy=validytemp;
 
325
        doitonemoretime=0;
 
326
    elseif selection_filter==2
 
327
        validx=validxtemp;
 
328
        validy=validytemp;
 
329
        doitonemoretime=1;
 
330
    elseif selection_filter==3
 
331
        doitonemoretime=1;
 
332
    elseif selection_filter==4
 
333
        return
 
334
    end
 
335
end
 
336
 
 
337
%---------------------------------
 
338
% Rotate Matrix
 
339
% written by Chris
 
340
function [validx, validy]=rotatematrix(validx,validy);
 
341
validxrot=validx;
 
342
clear validx;
 
343
validyrot=validy;
 
344
clear validy;
 
345
validy=validxrot;
 
346
validx=validyrot;
 
347
 
 
348
 
 
349
%---------------------------------
 
350
% Delete points from the displacement plot
 
351
% written by Chris
 
352
function [validx,validy,displx,disply] = removepoints_func(validx,validy,displx,disply) ; %delete points
 
353
 
 
354
close all
 
355
 
 
356
if exist('validx')==0
 
357
    [validx,Pathvalidx] = uigetfile('*.mat; *.txt','Open validx.mat or validx.txt');
 
358
    cd(Pathvalidx);
 
359
    validx=importdata(validx,'\t');
 
360
    [validy,Pathvalidy] = uigetfile('*.mat;*.txt','Open validy.mat or validy.txt');
 
361
    cd(Pathvalidy);
 
362
    validy=importdata(validy,'\t');
 
363
end
 
364
 
 
365
selectremove1 = menu(sprintf('Do you want to delete makers?'),'Yes','No');
 
366
if selectremove1==2
 
367
    return
 
368
end
 
369
 
 
370
% if yes
 
371
if selectremove1==1
 
372
 
 
373
    sizevalidx=size(validx);
 
374
    sizevalidy=size(validy);
 
375
 
 
376
    selectionremove2=selectremove1;
 
377
    counter=0
 
378
    sizevalidx=size(validx);
 
379
    looppoints=sizevalidx(1,1);
 
380
    loopimages=sizevalidx(1,2);
 
381
    defaultimage=loopimages
 
382
    numberbadpoints=0
 
383
 
 
384
    while selectionremove2==1
 
385
        counter=counter+1
 
386
        clear xplot
 
387
        clear sizevalidx
 
388
        clear selectremove11
 
389
        clear selection2
 
390
        %         clear badpoints
 
391
 
 
392
        sizevalidx=size(validx);
 
393
        looppoints=sizevalidx(1,1);
 
394
        loopimages=sizevalidx(1,2);
 
395
 
 
396
        % update temporary matrices
 
397
        validxtemp=validx;
 
398
        validytemp=validy;
 
399
        displxtemp=displx;
 
400
        displytemp=disply;
 
401
 
 
402
        % get the image number from which the bad points will be chosen
 
403
        prompt = {'From which image do you want to delete markers?'};
 
404
        dlg_title = 'Marker removal';
 
405
        num_lines= 1;
 
406
        if numberbadpoints==0
 
407
            defaultimage=loopimages
 
408
        end
 
409
        if numberbadpoints~0
 
410
            defaultimage=numberbadpoints
 
411
        end
 
412
        def     = {num2str(defaultimage)};
 
413
        answer = inputdlg(prompt,dlg_title,num_lines,def);
 
414
        numberbadpoints = str2num(cell2mat(answer(1,1)));
 
415
        if numberbadpoints>loopimages
 
416
            numberbadpoints=loopimages
 
417
        end
 
418
        if numberbadpoints<1
 
419
            numberbadpoints=1
 
420
        end
 
421
 
 
422
%         displx(:,1)=-validx(:,1)+validx(:,numberbadpoints);
 
423
%         disply(:,1)=-validy(:,1)+validy(:,numberbadpoints);
 
424
 
 
425
        plot(validx(:,numberbadpoints),displx(:,numberbadpoints),'o');
 
426
        xlabel('position [pixel]')
 
427
        ylabel('displacement [pixel]')
 
428
        title(['Displacement versus position',sprintf(' (Current image #: %1g)',numberbadpoints)]);
 
429
 
 
430
%         validxtemp=validx;
 
431
%         validytemp=validy;
 
432
        displxtemp=displx;
 
433
        validxdelete=validxtemp;
 
434
        validydelete=validytemp;
 
435
        displxdelete=displxtemp;
 
436
        displydelete=displytemp;
 
437
 
 
438
        title(sprintf('Define the region of interest.  \n  All points ouside that region will be deleted'))
 
439
 
 
440
        [xgrid,ygrid]=ginput(2);
 
441
        x(1,1) = xgrid(1);
 
442
        x(1,2) = xgrid(2);
 
443
        y(1,1) = ygrid(2);
 
444
        y(1,2) = ygrid(1);
 
445
 
 
446
        deletepoints=find(validxdelete(:,numberbadpoints)>min(x) & validxdelete(:,numberbadpoints)<max(x) & displxdelete(:,numberbadpoints)<max(y) & displxdelete(:,numberbadpoints)>min(y));
 
447
        [loopnum one]=size(deletepoints);
 
448
 
 
449
        validxdelete(deletepoints,:)=[];
 
450
        validydelete(deletepoints,:)=[];
 
451
 
 
452
 
 
453
        % update temporary data matrices; delete bad points
 
454
        displxtemp(deletepoints,:)=[];
 
455
        displytemp(deletepoints,:)=[];
 
456
        validxtemp(deletepoints,:)=[];
 
457
        validytemp(deletepoints,:)=[];
 
458
 
 
459
        plot(validxtemp(:,numberbadpoints),displxtemp(:,numberbadpoints),'o');
 
460
 
 
461
        % delete point permanently?
 
462
        selectremove3 = menu(sprintf('Do you want to delete these markers permanently?'),'Yes','No');
 
463
        if selectremove3==1
 
464
            displx=displxtemp;
 
465
            disply=displytemp;
 
466
            validx=validxtemp;
 
467
            validy=validytemp;
 
468
        end
 
469
        if selectremove3==2
 
470
            displxtemp=displx;
 
471
            displytemp=disply;
 
472
            validxtemp=validx;
 
473
            validytemp=validy;
 
474
        end
 
475
        selectremove2 = menu(sprintf('Do you want to mark another bad point?'),'Yes','No');
 
476
        if selectremove2==2
 
477
            clear displx;
 
478
            clear disply;
 
479
            validxfirst=zeros(size(validx));
 
480
            validxfirst=validx(:,1)*ones(1,sizevalidx(1,2));
 
481
            validyfirst=zeros(size(validy));
 
482
            validyfirst=validy(:,1)*ones(1,sizevalidy(1,2));
 
483
            displx=validx-validxfirst;
 
484
            disply=validy-validyfirst;
 
485
            return
 
486
        end
 
487
    end
 
488
 
 
489
end
 
490
 
 
491
%---------------------------------
 
492
% Delete single points
 
493
% written by Chris
 
494
function [validx,validy]=removepoints_func3(validx,validy);
 
495
 
 
496
%sort out badpoints?
 
497
 
 
498
selection1 = menu(sprintf('Do you want to mark bad points?'),'Yes','No');
 
499
if selection1==2
 
500
    close all;
 
501
    return
 
502
end
 
503
 
 
504
% if yes
 
505
if selection1==1
 
506
    selection2=selection1;
 
507
    %     figure
 
508
    counter=0
 
509
    sizevalidx=size(validx);
 
510
    looppoints=sizevalidx(1,1);
 
511
    loopimages=sizevalidx(1,2)-1;
 
512
    defaultimage=loopimages
 
513
    numberbadpoints=0
 
514
 
 
515
    while selection2==1
 
516
        counter=counter+1
 
517
        clear xplot
 
518
        clear sizevalidx
 
519
        clear selection1
 
520
        clear selection2
 
521
        clear badpoints
 
522
 
 
523
        sizevalidx=size(validx);
 
524
        looppoints=sizevalidx(1,1);
 
525
        loopimages=sizevalidx(1,2)-1;
 
526
 
 
527
        clear displx;
 
528
        validxfirst=zeros(size(validx));
 
529
        validxfirst=validx(:,1)*ones(1,sizevalidx(1,2));
 
530
        displx=validx-validxfirst;
 
531
 
 
532
        % update temporary matrices
 
533
        displxtemp=displx;
 
534
        validxtemp=validx;
 
535
        validytemp=validy;
 
536
        %         resnormxtemp=resnormx;
 
537
 
 
538
        % get the image number from which the bad points will be chosen
 
539
        prompt = {'From which image do you want to choose the bad points?'};
 
540
        dlg_title = 'Bad points removal';
 
541
        num_lines= 1;
 
542
        if numberbadpoints==0
 
543
            defaultimage=loopimages
 
544
        end
 
545
        if numberbadpoints~0
 
546
            defaultimage=numberbadpoints
 
547
        end
 
548
        def     = {num2str(defaultimage)};
 
549
        answer = inputdlg(prompt,dlg_title,num_lines,def);
 
550
        numberbadpoints = str2num(cell2mat(answer(1,1)));
 
551
        if numberbadpoints>loopimages
 
552
            numberbadpoints=loopimages
 
553
        end
 
554
        if numberbadpoints<1
 
555
            numberbadpoints=1
 
556
        end
 
557
 
 
558
        gridsizex=10*round(min(min(validx))/10):10:10*round(max(max(validx))/10);
 
559
        gridsizey=10*round(min(min(validy))/10):10:10*round(max(max(validy))/10);
 
560
        [XI,YI]=meshgrid(gridsizex,gridsizey);
 
561
        ZI=griddata(validx(:,numberbadpoints),validy(:,numberbadpoints),displx(:,numberbadpoints),XI,YI,'cubic');
 
562
        epsxx = gradient(ZI,10,10);
 
563
 
 
564
        % find max and min point and point them out
 
565
        mindisplx=find(displx(:,numberbadpoints)==min(displx(:,numberbadpoints)));
 
566
        maxdisplx=find(displx(:,numberbadpoints)==max(displx(:,numberbadpoints)));
 
567
 
 
568
 
 
569
        pcolor(XI,YI,epsxx);
 
570
        axis('equal')
 
571
        caxis([min(min(epsxx)) max(max(epsxx))])
 
572
        colorbar
 
573
        shading('interp')
 
574
        hold on
 
575
        plot3(validx(:,numberbadpoints),validy(:,numberbadpoints),displx(:,numberbadpoints)-min(displx(:,numberbadpoints)),'o','MarkerEdgeColor','k','MarkerFaceColor','g'), hold on;
 
576
        plot3(validx(mindisplx,numberbadpoints),validy(mindisplx,numberbadpoints),displx(mindisplx,numberbadpoints)-min(displx(:,numberbadpoints)),'o','MarkerEdgeColor','y','MarkerFaceColor','b')
 
577
        plot3(validx(maxdisplx,numberbadpoints),validy(maxdisplx,numberbadpoints),displx(maxdisplx,numberbadpoints)-min(displx(:,numberbadpoints)),'o','MarkerEdgeColor','y','MarkerFaceColor','r')
 
578
        axis([min(min(XI))-10 max(max(XI))+10 min(min(YI))-10 max(max(YI))+10])
 
579
        drawnow;
 
580
        hold off
 
581
 
 
582
        % get the bad point position
 
583
 
 
584
        title(sprintf('Click on the bad point',counter))
 
585
        [badpoint]=ginput(1);
 
586
        badpointx = badpoint(1,1);
 
587
        badpointy = badpoint(1,2);
 
588
 
 
589
        % find the point matching the given position
 
590
        wherethehellisthispoint=abs(validx(:,numberbadpoints)-badpoint(1,1))+abs(validy(:,numberbadpoints)-badpoint(1,2));
 
591
        badpointnum=find(wherethehellisthispoint==min(wherethehellisthispoint));
 
592
 
 
593
        % update temporary data matrices; delete bad points
 
594
 
 
595
        displxtemp(badpointnum,:)=[];
 
596
        validxtemp(badpointnum,:)=[];
 
597
        validytemp(badpointnum,:)=[];
 
598
        mindisplx=find(displxtemp(:,numberbadpoints)==min(displxtemp(:,numberbadpoints)));
 
599
        maxdisplx=find(displxtemp(:,numberbadpoints)==max(displxtemp(:,numberbadpoints)));
 
600
 
 
601
        % update the figure
 
602
        ZI=griddata(validxtemp(:,numberbadpoints),validytemp(:,numberbadpoints),displxtemp(:,numberbadpoints),XI,YI,'cubic');
 
603
        epsxx = gradient(ZI,10,10);
 
604
        pcolor(XI,YI,epsxx);
 
605
        axis('equal')
 
606
        caxis([min(min(epsxx)) max(max(epsxx))])
 
607
        colorbar
 
608
        shading('interp')
 
609
        hold on
 
610
        plot3(validxtemp(:,numberbadpoints),validytemp(:,numberbadpoints),displxtemp(:,numberbadpoints),'o','MarkerEdgeColor','k','MarkerFaceColor','g')
 
611
        plot3(validxtemp(mindisplx,numberbadpoints),validytemp(mindisplx,numberbadpoints),displxtemp(mindisplx,numberbadpoints)-min(displxtemp(:,numberbadpoints)),'o','MarkerEdgeColor','y','MarkerFaceColor','b')
 
612
        plot3(validxtemp(maxdisplx,numberbadpoints),validytemp(maxdisplx,numberbadpoints),displxtemp(maxdisplx,numberbadpoints)-min(displxtemp(:,numberbadpoints)),'o','MarkerEdgeColor','y','MarkerFaceColor','r')
 
613
        axis([min(min(XI))-10 max(max(XI))+10 min(min(YI))-10 max(max(YI))+10])
 
614
        drawnow;hold off;
 
615
 
 
616
        % delete point permanently?
 
617
        selection3 = menu(sprintf('Do you want to delete this point permanently?'),'Yes','No');
 
618
        if selection3==1
 
619
            displx=displxtemp;
 
620
            validx=validxtemp;
 
621
            validy=validytemp;
 
622
            %             resnormx=resnormxtemp;
 
623
        end
 
624
        if selection3==2
 
625
            displxtemp=displx;
 
626
            validxtemp=validx;
 
627
            validytemp=validy;
 
628
            %             resnormxtemp=resnormx;
 
629
        end
 
630
        selection2 = menu(sprintf('Do you want to mark another bad point?'),'Yes','No');
 
631
        if selection2==2
 
632
            close all;
 
633
            return
 
634
        end
 
635
 
 
636
    end
 
637
end
 
638
 
 
639
%---------------------------------
 
640
% Strain between two markers
 
641
% written by Chris
 
642
function [validx, validy,displx,disply] = strain_1D_2Points_func(validx, validy,displx,disply) ; % 1D strain calculation
 
643
 
 
644
sizevalidx=size(validx);
 
645
looppoints=sizevalidx(1,1);
 
646
loopimages=sizevalidx(1,2)-1;
 
647
defaultimage=loopimages;
 
648
numberbadpoints=0;
 
649
clear selection3; selection3=1;
 
650
 
 
651
while selection3==1
 
652
 
 
653
    clear xplot
 
654
    clear sizevalidx
 
655
    clear selection1
 
656
    clear selection2
 
657
    clear badpoints
 
658
 
 
659
    sizevalidx=size(validx);
 
660
    looppoints=sizevalidx(1,1);
 
661
    loopimages=sizevalidx(1,2)-1;
 
662
 
 
663
    % update temporary matrices
 
664
    displxtemp=displx;
 
665
    validxtemp=validx;
 
666
    validytemp=validy;
 
667
    %     resnormxtemp=resnormx;
 
668
 
 
669
    % get the image number from which the bad points will be chosen
 
670
    prompt = {'Which image do you want for point selection?'};
 
671
    dlg_title = '1D Strain Plotting';
 
672
    num_lines= 1;
 
673
    if numberbadpoints==0
 
674
        defaultimage=loopimages;
 
675
    end
 
676
    if numberbadpoints~0
 
677
        defaultimage=numberbadpoints
 
678
    end
 
679
    def     = {num2str(defaultimage)};
 
680
    answer = inputdlg(prompt,dlg_title,num_lines,def);
 
681
    numberbadpoints = str2num(cell2mat(answer(1,1)));
 
682
    if numberbadpoints>loopimages
 
683
        numberbadpoints=loopimages;
 
684
    end
 
685
    if numberbadpoints<1
 
686
        numberbadpoints=1;
 
687
    end
 
688
 
 
689
    gridsizex=10*round(min(min(validx))/10):10:10*round(max(max(validx))/10);
 
690
    gridsizey=10*round(min(min(validy))/10):10:10*round(max(max(validy))/10);
 
691
    [XI,YI]=meshgrid(gridsizex,gridsizey);
 
692
    ZI=griddata(validx(:,numberbadpoints),validy(:,numberbadpoints),displx(:,numberbadpoints),XI,YI,'cubic');
 
693
 
 
694
    pcolor(XI,YI,ZI);
 
695
    axis('equal')
 
696
    caxis([min(min(ZI)) max(max(ZI))])
 
697
    colorbar
 
698
    shading('interp')
 
699
    hold on
 
700
    plot3(validx(:,numberbadpoints),validy(:,numberbadpoints),abs(displx(:,numberbadpoints)),'o','MarkerEdgeColor','k','MarkerFaceColor','g');
 
701
    axis([min(min(XI))-10 max(max(XI))+10 min(min(YI))-10 max(max(YI))+10])
 
702
    drawnow;
 
703
 
 
704
    % get the bad point position
 
705
 
 
706
    title(sprintf('Click on the two points for strain measurement'))
 
707
    [badpoint]=ginput(2);
 
708
    badpointx = badpoint(1,1);
 
709
    badpointy = badpoint(1,2);
 
710
    badpointx2 = badpoint(2,1);
 
711
    badpointy2 = badpoint(2,2);
 
712
 
 
713
    % find the point matching the given position
 
714
    wherethehellisthispoint=abs(validx(:,numberbadpoints)-badpoint(1,1))+abs(validy(:,numberbadpoints)-badpoint(1,2));
 
715
    badpointnum=find(wherethehellisthispoint==min(wherethehellisthispoint));
 
716
    wherethehellisthispoint2=abs(validx(:,numberbadpoints)-badpoint(2,1))+abs(validy(:,numberbadpoints)-badpoint(2,2));
 
717
    badpointnum2=find(wherethehellisthispoint2==min(wherethehellisthispoint2));
 
718
 
 
719
 
 
720
    % update the figure
 
721
    ZI=griddata(validxtemp(:,numberbadpoints),validytemp(:,numberbadpoints),displxtemp(:,numberbadpoints),XI,YI,'cubic');
 
722
    caxis([min(min(ZI)) max(max(ZI))])
 
723
    plot3(validxtemp(badpointnum,numberbadpoints),validytemp(badpointnum,numberbadpoints),displxtemp(badpointnum,numberbadpoints),'+','MarkerEdgeColor','k','MarkerFaceColor','g')
 
724
    plot3(validxtemp(badpointnum2,numberbadpoints),validytemp(badpointnum2,numberbadpoints),displxtemp(badpointnum2,numberbadpoints),'+','MarkerEdgeColor','k','MarkerFaceColor','r')
 
725
    hold off;
 
726
    axis([min(min(XI))-10 max(max(XI))+10 min(min(YI))-10 max(max(YI))+10])
 
727
    drawnow;
 
728
 
 
729
    epsilon1D=(displxtemp(badpointnum,:)-displxtemp(badpointnum2,:))/(validxtemp(badpointnum,1)-validxtemp(badpointnum2,1));
 
730
    epsilonsize=size(epsilon1D);
 
731
    figure; plot(1:epsilonsize(1,2),epsilon1D,'.');
 
732
    title(['True strain versus image from two picked points']);
 
733
    xlabel('Image number [ ]');
 
734
    ylabel('True Strain [ ]');
 
735
 
 
736
 
 
737
    selection3 = menu(sprintf('Do you want to choose 2 other points?'),'Yes','No');
 
738
 
 
739
    if selection3==2
 
740
        selection40 = menu(sprintf('Do you want to save the data as a text file?'),'Yes','No');
 
741
        if selection40==2
 
742
            return
 
743
        end
 
744
        if selection40==1
 
745
            numimagtemp = [1:epsilonsize(1,2)]';
 
746
            alltemp = [numimagtemp epsilon1D'];
 
747
            [FileNameBase,PathNameBase] = uiputfile('','Save file with image# vs. 1Dstrain');
 
748
            cd(PathNameBase)
 
749
            save(FileNameBase,'alltemp','-ASCII');
 
750
            %             save image_1Dstrain.txt alltemp -ASCII
 
751
            return
 
752
        end
 
753
    end
 
754
    close(gcf)
 
755
end
 
756
%---------------------------------
 
757
% Measure elastic slope
 
758
% written by Chris
 
759
function [validx, validy,displx,disply] = strain_1D_average_func(validx, validy,displx,disply) ; % 1D strain calculation
 
760
videoselection = menu(sprintf('Do you want to create a video?'),'Yes','No');
 
761
if videoselection==1
 
762
    mkdir('videostrain')
 
763
    cd('videostrain');
 
764
    Vid='Vid';
 
765
end
 
766
selection50=1;
 
767
validx_fit=validx;
 
768
displx_fit=displx;
 
769
minminvalidx=min(min(validx));
 
770
maxmaxvalidx=max(max(validx));
 
771
minminvalidy=min(min(validy));
 
772
maxmaxvalidy=max(max(validy));
 
773
minmindisplx=min(min(displx));
 
774
maxmaxdisplx=max(max(displx));
 
775
h= figure
 
776
while selection50==1
 
777
    %     figure
 
778
    [pointnumber imagenumber]=size(displx);
 
779
    for i=1:imagenumber;
 
780
        plot(validx_fit(:,i),displx_fit(:,i),'o');
 
781
        xdata=validx_fit(:,i);
 
782
        ydata=displx_fit(:,i);
 
783
        if i==1
 
784
            x(1)=0
 
785
            x(2)=0
 
786
        end
 
787
        [x,resnormx,residual,exitflagx,output]  = lsqcurvefit(@linearfit, [x(1) x(2)], xdata, ydata);
 
788
        hold on;
 
789
        ydatafit=x(1)*xdata+x(2);
 
790
        plot(xdata,ydatafit,'r');
 
791
        
 
792
        hold off
 
793
        slope(i,:)=[i x(1)];
 
794
        axis([minminvalidx maxmaxvalidx minmindisplx maxmaxdisplx])
 
795
        xlabel('position [pixel]')
 
796
        ylabel('displacement [pixel]')
 
797
        title(['Displacement versus position',sprintf(' (Current image #: %1g)',i)]);
 
798
        drawnow
 
799
        if videoselection==1
 
800
            u=i+10000;
 
801
            ustr=num2str(u);
 
802
            videoname=[Vid ustr '.jpg']
 
803
            saveas(h,videoname,'jpg')
 
804
        end
 
805
    end
 
806
    g1 = figure, plot(slope(:,1),slope(:,2));
 
807
    hold on
 
808
    plot(slope(:,1),slope(:,2),'.');
 
809
        xlabel('Image [ ]')
 
810
        ylabel('True Strain [ ]')
 
811
        title(['True Strain vs. Image #']);
 
812
 
 
813
    selection40 = menu(sprintf('Do you want to save the data as file?'),'Yes','No');
 
814
    if selection40==2
 
815
 
 
816
    end
 
817
    if selection40==1
 
818
        alltemp = [slope(:,1) slope(:,2)];
 
819
        [FileNameBase,PathNameBase] = uiputfile('','Save file with image# vs. 1Dstrain');
 
820
        cd(PathNameBase)
 
821
        save(FileNameBase,'alltemp','-ASCII');
 
822
        %         save image_1Dstrain_avg.txt alltemp -ASCII
 
823
    end
 
824
 
 
825
    selection50 = menu(sprintf('Do you want to analyse a selected area again?'),'Yes','No');
 
826
    if selection50==2
 
827
        clear validx_fit
 
828
        clear displx_fit
 
829
        return
 
830
    end
 
831
    if selection50==1
 
832
        close(g1)
 
833
        plot(validx_fit(:,imagenumber),displx_fit(:,imagenumber),'o');
 
834
        title(['True strain versus image from all markers']);
 
835
        xlabel('Image number [ ]');
 
836
        ylabel('True Strain [ ]');
 
837
        prompt = {'Min. x-position:','Max. x-position:'};
 
838
        dlg_title = 'Regime to be analyzed in pixels';
 
839
        num_lines= 1;
 
840
        def     = {'800','1200'};
 
841
        answer = inputdlg(prompt,dlg_title,num_lines,def);
 
842
        minx= str2num(cell2mat(answer(1,1)));
 
843
        maxx= str2num(cell2mat(answer(2,1)));
 
844
        counter=0
 
845
        clear validx_fit
 
846
        clear displx_fit
 
847
        selectedmarkers=find(validx(:,imagenumber)>minx  & validx(:,imagenumber)<maxx);
 
848
        validx_fit=validx(selectedmarkers,:);
 
849
        displx_fit=displx(selectedmarkers,:);
 
850
        continue
 
851
    end
 
852
 
 
853
end
 
854
 
 
855
 
 
856
%---------------------------------
 
857
% 3D mesh plotting
 
858
% written by Chris
 
859
function [validx, validy,displx,disply]=meshplot(validx,validy,displx,disply);
 
860
h=figure;
 
861
sizevalidx=size(validx);
 
862
sizevalidy=size(validy);
 
863
looppoints=sizevalidx(1,1);
 
864
loopimages=sizevalidx(1,2);
 
865
 
 
866
videoselection = menu(sprintf('Do you want to create a video?'),'Yes','No');
 
867
if videoselection==1
 
868
    mkdir('video')
 
869
    cd('video');
 
870
    Vid='Vid';
 
871
end
 
872
gridsizex=10*round(min(min(validx))/10):10:10*round(max(max(validx))/10);
 
873
gridsizey=10*round(min(min(validy))/10):10:10*round(max(max(validy))/10);
 
874
[XI,YI]=meshgrid(gridsizex,gridsizey);
 
875
minminvalidx=min(min(validx));
 
876
maxmaxvalidx=max(max(validx));
 
877
minminvalidy=min(min(validy));
 
878
maxmaxvalidy=max(max(validy));
 
879
minmindisplx=min(min(displx));
 
880
maxmaxdisplx=max(max(displx));
 
881
minmindisply=min(min(disply));
 
882
maxmaxdisply=max(max(disply));
 
883
for i=1:(loopimages-1)
 
884
    ZI=griddata(validx(:,i),validy(:,i),displx(:,i),XI,YI,'cubic');
 
885
    mesh(XI,YI,ZI); hold on
 
886
    bottomplot=ones(size(validx))*minmindisplx;
 
887
    backyplaneplot=ones(size(validx))*maxmaxvalidy;
 
888
    backxplaneplot=ones(size(validx))*minminvalidx;
 
889
    plot3(validx(:,i),validy(:,i),displx(:,i),'.b');
 
890
    %         plot3(validx(:,i),backyplaneplot(:,i),displx(:,i),'.');
 
891
    plot3(backxplaneplot(:,i),validy(:,i),displx(:,i),'.g');
 
892
    xlabel('x-position [pixel]')
 
893
    ylabel('y-position [pixel]')
 
894
    zlabel('displacement [pixel]')
 
895
    %         plot3(validx(:,i),validy(:,i),bottomplot(:,i),'.');
 
896
    hold off
 
897
    title(['Displacement versus x-y-position',sprintf(' (Current image #: %1g)',i)]);
 
898
    axis([minminvalidx maxmaxvalidx minminvalidy maxmaxvalidy minmindisplx maxmaxdisplx])
 
899
    drawnow
 
900
    if videoselection==1
 
901
        u=i+10000;
 
902
        ustr=num2str(u);
 
903
        videoname=[Vid ustr '.jpg']
 
904
        saveas(h,videoname,'jpg')
 
905
    end
 
906
end
 
907
 
 
908
if videoselection==1
 
909
    cd('..')
 
910
end
 
911
 
 
912
%-------------------------------
 
913
% polyfit function
 
914
% written by Dan slightly changed by Chris
 
915
function [validx, validy,displx,disply]=polyfit3D(validx, validy,displx,disply);
 
916
close all
 
917
plot3dsurface_func(validx,validy,displx);
 
918
 
 
919
%---------------------------------------
 
920
% Just plot it
 
921
% written by Dan slightly changed by Chris
 
922
function plot3dsurface_func(validx,validy,displx,gridstyle,cropxx,cropyy)
 
923
 
 
924
sizevalidx=size(validx);
 
925
looppoints=sizevalidx(1,1);
 
926
loopimages=sizevalidx(1,2);
 
927
gridsizex=10*round(min(min(validx))/10):10:10*round(max(max(validx))/10);
 
928
gridsizey=10*round(min(min(validy))/10):10:10*round(max(max(validy))/10);
 
929
[XI,YI]=meshgrid(gridsizex,gridsizey);
 
930
ZI=griddata(validx(:,1),validy(:,1),displx(:,1),XI,YI,'cubic');
 
931
ZIsize=size(ZI);
 
932
displcolor = [-7 1];
 
933
straincolor = [-0.005 0.03];
 
934
 
 
935
maxminusminvalidx=(max(max(validx))-min(min(validx)));
 
936
maxminusminvalidy=(max(max(validx))-min(min(validy)));
 
937
 
 
938
for i=1:(loopimages-1)
 
939
 
 
940
    ZI=griddata(validx(:,i),validy(:,i),displx(:,i),XI,YI,'cubic');
 
941
    ZIsize=size(ZI);
 
942
    epsxx = gradient(ZI,(maxminusminvalidx/ZIsize(1,1)),(maxminusminvalidy/ZIsize(1,2)));
 
943
 
 
944
    subplot(2,1,1)
 
945
    pcolor(XI,YI,ZI)
 
946
    axis('equal')
 
947
    shading('interp')
 
948
    caxis(displcolor)
 
949
    h1 = colorbar;
 
950
    set(h1, 'PlotBoxAspectRatio',[2.0 10 8.0])
 
951
    set(h1, 'FontSize', 12);
 
952
    title(['Raw Displacement in x-direction',sprintf(' (Current image #: %1g)',i)]);
 
953
 
 
954
    subplot(2,1,2)
 
955
    pcolor(XI,YI,epsxx)
 
956
    axis('equal')
 
957
    shading('interp')
 
958
    caxis(straincolor)
 
959
    h1 = colorbar;
 
960
    set(h1, 'PlotBoxAspectRatio',[2.0 10 8.0])
 
961
    set(h1, 'FontSize', 12);
 
962
    title('Raw Strain in x-direction');
 
963
 
 
964
    drawnow
 
965
 
 
966
end
 
967
 
 
968
%--------------------------------------
 
969
% Delete some markers
 
970
% written by Chris
 
971
function [validx,validy] = removepoints_func2(validx,validy) ; %delete points
 
972
 
 
973
if exist('validx')==0
 
974
    [validx,Pathvalidx] = uigetfile('*.mat; *.txt','Open validx.mat or validx.txt');
 
975
    cd(Pathvalidx);
 
976
    validx=importdata(validx,'\t');
 
977
    [validy,Pathvalidy] = uigetfile('*.mat;*.txt','Open validy.mat or validy.txt');
 
978
    cd(Pathvalidy);
 
979
    validy=importdata(validy,'\t');
 
980
end
 
981
 
 
982
 
 
983
selectremove1 = menu(sprintf('Do you want to delete makers?'),'Yes','No');
 
984
if selectremove1==2
 
985
 
 
986
    return
 
987
end
 
988
 
 
989
% if yes
 
990
if selectremove1==1
 
991
    selectionremove2=selectremove1;
 
992
    %     figure
 
993
    counter=0
 
994
    sizevalidx=size(validx);
 
995
    looppoints=sizevalidx(1,1);
 
996
    loopimages=sizevalidx(1,2);
 
997
    defaultimage=loopimages
 
998
    numberbadpoints=0
 
999
 
 
1000
    while selectionremove2==1
 
1001
        counter=counter+1
 
1002
        clear xplot
 
1003
        clear sizevalidx
 
1004
        clear selectremove11
 
1005
        clear selection2
 
1006
        %         clear badpoints
 
1007
 
 
1008
        sizevalidx=size(validx);
 
1009
        looppoints=sizevalidx(1,1);
 
1010
        loopimages=sizevalidx(1,2);
 
1011
 
 
1012
        % update temporary matrices
 
1013
        %         displxtemp=displx;
 
1014
        validxtemp=validx;
 
1015
        validytemp=validy;
 
1016
        %         resnormxtemp=resnormx;
 
1017
 
 
1018
        % get the image number from which the bad points will be chosen
 
1019
        prompt = {'From which image do you want to delete markers?'};
 
1020
        dlg_title = 'Marker removal';
 
1021
        num_lines= 1;
 
1022
        if numberbadpoints==0
 
1023
            defaultimage=loopimages
 
1024
        end
 
1025
        if numberbadpoints~0
 
1026
            defaultimage=numberbadpoints
 
1027
        end
 
1028
        def     = {num2str(defaultimage)};
 
1029
        answer = inputdlg(prompt,dlg_title,num_lines,def);
 
1030
        numberbadpoints = str2num(cell2mat(answer(1,1)));
 
1031
        if numberbadpoints>loopimages
 
1032
            numberbadpoints=loopimages
 
1033
        end
 
1034
        if numberbadpoints<1
 
1035
            numberbadpoints=1
 
1036
        end
 
1037
 
 
1038
        displx(:,1)=-validx(:,1)+validx(:,numberbadpoints);
 
1039
        displx(:,1)=displx(:,1)-min(displx(:,1));
 
1040
 
 
1041
        gridsizex=10*round(min(min(validx))/10):10:10*round(max(max(validx))/10);
 
1042
        gridsizey=10*round(min(min(validy))/10):10:10*round(max(max(validy))/10);
 
1043
        [XI,YI]=meshgrid(gridsizex,gridsizey);
 
1044
        ZI=griddata(validx(:,numberbadpoints),validy(:,numberbadpoints),displx(:,1),XI,YI,'cubic');
 
1045
        epsxx = gradient(ZI,10,10);
 
1046
 
 
1047
        pcolor(XI,YI,epsxx);
 
1048
        axis('equal')
 
1049
        caxis([min(min(epsxx)) max(max(epsxx))])
 
1050
        colorbar
 
1051
        shading('interp')
 
1052
        hold on
 
1053
        plot3(validx(:,numberbadpoints),validy(:,numberbadpoints),displx(:,1),'.','MarkerEdgeColor','k','MarkerFaceColor','g'), hold off;
 
1054
        axis([min(min(XI))-10 max(max(XI))+10 min(min(YI))-10 max(max(YI))+10])
 
1055
        drawnow;
 
1056
 
 
1057
        validxtemp=validx;
 
1058
        validytemp=validy;
 
1059
        displxtemp=displx;
 
1060
        validxdelete=validxtemp;
 
1061
        validydelete=validytemp;
 
1062
        displxdelete=displxtemp;
 
1063
 
 
1064
        title(sprintf('Define the region of interest.  \n  All points ouside that region will be deleted'))
 
1065
 
 
1066
        [xgrid,ygrid]=ginput(2);
 
1067
        x(1,1) = xgrid(1);
 
1068
        x(1,2) = xgrid(2);
 
1069
        y(1,1) = ygrid(2);
 
1070
        y(1,2) = ygrid(1);
 
1071
 
 
1072
        deletepoints=find(validxdelete(:,numberbadpoints)>min(x) & validxdelete(:,numberbadpoints)<max(x) & validydelete(:,numberbadpoints)<max(y) & validydelete(:,numberbadpoints)>min(y));
 
1073
        [loopnum one]=size(deletepoints);
 
1074
 
 
1075
        validxdelete(deletepoints,:)=[];
 
1076
        validydelete(deletepoints,:)=[];
 
1077
 
 
1078
        plot3(validxtemp(:,numberbadpoints),validytemp(:,numberbadpoints),displxtemp(:,1),'o','MarkerEdgeColor','k','MarkerFaceColor','g'), hold off;
 
1079
 
 
1080
        % update temporary data matrices; delete bad points
 
1081
        displxtemp(deletepoints,:)=[];
 
1082
        validxtemp(deletepoints,:)=[];
 
1083
        validytemp(deletepoints,:)=[];
 
1084
 
 
1085
        % update the figure
 
1086
        gridsizex=10*round(min(min(validxtemp))/10):10:10*round(max(max(validxtemp))/10);
 
1087
        gridsizey=10*round(min(min(validytemp))/10):10:10*round(max(max(validytemp))/10);
 
1088
        [XI,YI]=meshgrid(gridsizex,gridsizey);
 
1089
        ZI=griddata(validxtemp(:,numberbadpoints),validytemp(:,numberbadpoints),displxtemp(:,1),XI,YI,'cubic');
 
1090
        epsxx = gradient(ZI,10,10);
 
1091
        pcolor(XI,YI,epsxx);
 
1092
        axis('equal')
 
1093
        caxis([min(min(epsxx)) max(max(epsxx))])
 
1094
        colorbar
 
1095
        shading('interp')
 
1096
        hold on
 
1097
        plot3(validxtemp(:,numberbadpoints),validytemp(:,numberbadpoints),displxtemp(:,1),'o','MarkerEdgeColor','k','MarkerFaceColor','g'), hold off;
 
1098
        axis([min(min(XI))-10 max(max(XI))+10 min(min(YI))-10 max(max(YI))+10])
 
1099
        drawnow;
 
1100
 
 
1101
        % delete point permanently?
 
1102
        selectremove3 = menu(sprintf('Do you want to delete these markers permanently?'),'Yes','No');
 
1103
        if selectremove3==1
 
1104
            displx=displxtemp;
 
1105
            validx=validxtemp;
 
1106
            validy=validytemp;
 
1107
        end
 
1108
        if selectremove3==2
 
1109
            displxtemp=displx;
 
1110
            validxtemp=validx;
 
1111
            validytemp=validy;
 
1112
        end
 
1113
        selectremove2 = menu(sprintf('Do you want to mark another bad point?'),'Yes','No');
 
1114
        if selectremove2==2
 
1115
            clear displx;
 
1116
            validxfirst=zeros(size(validx));
 
1117
            validxfirst=validx(:,1)*ones(1,sizevalidx(1,2));
 
1118
            displx=validx-validxfirst;
 
1119
            return
 
1120
        end
 
1121
    end
 
1122
end
 
 
b'\\ No newline at end of file'