-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBarrett_method_multiple_SV.m
717 lines (488 loc) · 18.5 KB
/
Barrett_method_multiple_SV.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
function varargout = Barrett_method_multiple_SV(varargin)
% BARRETT_METHOD_MULTIPLE_SV MATLAB code for Barrett_method_multiple_SV.fig
% BARRETT_METHOD_MULTIPLE_SV, by itself, creates a new BARRETT_METHOD_MULTIPLE_SV or raises the existing
% singleton*.
%
% H = BARRETT_METHOD_MULTIPLE_SV returns the handle to a new BARRETT_METHOD_MULTIPLE_SV or the handle to
% the existing singleton*.
%
% BARRETT_METHOD_MULTIPLE_SV('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in BARRETT_METHOD_MULTIPLE_SV.M with the given input arguments.
%
% BARRETT_METHOD_MULTIPLE_SV('Property','Value',...) creates a new BARRETT_METHOD_MULTIPLE_SV or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Barrett_method_multiple_SV_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Barrett_method_multiple_SV_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 Barrett_method_multiple_SV
% Last Modified by GUIDE v2.5 25-Jun-2019 09:36:46
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Barrett_method_multiple_SV_OpeningFcn, ...
'gui_OutputFcn', @Barrett_method_multiple_SV_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 Barrett_method_multiple_SV is made visible.
function Barrett_method_multiple_SV_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 Barrett_method_multiple_SV (see VARARGIN)
% Choose default command line output for Barrett_method_multiple_SV
handles.output = hObject;
[num,txt,raw] = xlsread('Book_S.csv');
sz=size(raw);
for i=1:sz(2)
if(raw{2,i}~=47)
aaa=strrep(raw{4,i},'/','-');
aaa=strrep(aaa,'2002','2');
a=sprintf('PSD Fig %d %s Zone %s %s %s %s %s ',raw{2,i},raw{3,i},aaa,raw{5,i},raw{6,i},raw{7,i},raw{8,i});
b=sprintf('PSD Fig %d %s Zone %s %s \n%s %s %s ',raw{2,i},raw{3,i},aaa,raw{5,i},raw{6,i},raw{7,i},raw{8,i});
else
aaa=7;
a=sprintf('PSD Fig %d %s Zone %d %s %s %s %s ',raw{2,i},raw{3,i},aaa,raw{5,i},raw{6,i},raw{7,i},raw{8,i});
b=sprintf('PSD Fig %d %s Zone %d %s \n%s %s %s ',raw{2,i},raw{3,i},aaa,raw{5,i},raw{6,i},raw{7,i},raw{8,i});
end
b=strrep(b,'LONG','Long');
b=strrep(b,'TANGENT','Tangent');
b=strrep(b,'RADIAL','Radial');
b=strrep(b,'NORMAL','Normal');
b=strrep(b,'LIFTOFF','Liftoff');
b=strrep(b,'MACH','Mach');
b=strrep(b,'MAX','Max');
b=strrep(b,'STATIC','Static');
title{i}=a;
title2{i}=b;
end
str0={'psd_f12';'psd_f14';'psd_f16';'psd_f18';'psd_f20';'psd_f21';'psd_f22';...
'psd_f23';'psd_f24';'psd_f25';'psd_f26';'psd_f27';'psd_f30';'psd_f32';...
'psd_f34';'psd_f35';'psd_f40';'psd_f41';'psd_f42';'psd_f44';'psd_f47';...
'psd_f51';'psd_f53';'psd_f56';'psd_f58';'psd_f60';'psd_f62';'psd_f64';...
'psd_f65';'psd_f66';'psd_f67';'psd_f71';'psd_f73';'psd_f75';'psd_f77';...
'psd_f78';'psd_f79';'psd_f81';'psd_f83';'psd_f85';'psd_f87';'psd_f89';...
'psd_f91';'psd_f93';'psd_f94';'psd_f95';'psd_f96';'psd_f97';'psd_f98';...
'psd_f104';'psd_f106';'psd_f108';'psd_f110';'psd_f112';'psd_f113'};
str1={ 'spl_f13_int';'spl_f15_int';'spl_f17_int';'spl_f19_int';'spl_f31_int';...
'spl_f33_int';'spl_f36_int';'spl_f43_int';'spl_f45_int';'spl_f48_int';...
'spl_f52_int';'spl_f54_int';'spl_f57_int';'spl_f59_int';'spl_f61_int';...
'spl_f63_int';'spl_f72_int';'spl_f74_int';'spl_f76_int';'spl_f80_int';...
'spl_f84_int';'spl_f86_int';'spl_f88_int';'spl_f90_int';'spl_f92_int';...
'spl_f105_int';'spl_f107_int';'spl_f109_int';'spl_f111_int';'spl_f114_int'};
n=60;
for i=1:n
myData{i,1}='';
myData{i,2}='choose';
myData{i,3}='choose';
myData{i,4}='';
end
set(handles.uitable_data,'ColumnFormat',({[] str0' str1' []}),...
'ColumnEditable', true,...
'Data', myData);
listbox_num_Callback(hObject, eventdata, handles);
setappdata(0,'str0',str0);
setappdata(0,'title',title);
setappdata(0,'title2',title2);
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Barrett_method_multiple_SV wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Barrett_method_multiple_SV_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 pushbutton_calculate.
function pushbutton_calculate_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_calculate (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disp(' ');
disp(' * * * * * * * * * * * * * * * * * * * * * * ');
disp(' ');
Figures = findobj( 'Type', 'Figure' , '-not' , 'Tag' , get( handles.output , 'Tag' ) );
NFigures = length( Figures );
for nFigures = 1 : NFigures
close( Figures( nFigures ) );
end
fig_num=1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
title=getappdata(0,'title');
title2=getappdata(0,'title2');
try
FS1=strtrim(get(handles.edit_ref_spl,'String'));
SPL_ref=evalin('base',FS1);
catch
warndlg('Reference SPL array not found ');
return;
end
szr=size(SPL_ref);
if(szr(2)~=2)
warndlg('Input Reference SPL array must have two columns');
return;
end
get_table_data(hObject, eventdata, handles);
t_string=getappdata(0,'t_string');
Ref_PSD=getappdata(0,'Ref_PSD');
New_SPL=getappdata(0,'New_SPL');
New_PSD=getappdata(0,'New_PSD');
%%%
ref_spl=SPL_ref;
sz=size(ref_spl);
nf_ref_spl=sz(1);
num=get(handles.listbox_num,'Value');
%
x_label='Frequency (Hz)';
y_label='Accel (G^2/Hz)';
disp(' ');
disp(' Output Arrays ');
disp(' ');
for i=1:num
try
FS1=strtrim(Ref_PSD{i});
ref_psd=evalin('base',FS1);
catch
out1=sprintf('Ref PSD array not found: %s',Ref_PSD{i});
warndlg(out1);
return;
end
try
FS2=strtrim(New_SPL{i});
new_spl=evalin('base',FS2);
catch
out1=sprintf('New SPL array not found: %s',New_SPL{i});
warndlg(out1);
return;
end
%%
sz=size(ref_psd);
nf_ref_psd=sz(1);
sz=size(new_spl);
nf_new_spl=sz(1);
if(nf_ref_spl~=nf_ref_psd)
warndlg('nf_ref_spl~=nf_ref_psd');
return;
end
if(nf_new_spl~=nf_ref_spl)
warndlg('nf_new_spl~=nf_ref_spl');
return;
end
new_psd=zeros(nf_ref_psd,2);
for j=1:nf_ref_psd
delta_dB=new_spl(j,2)-ref_spl(j,2);
scale=10^(delta_dB/10);
new_psd(j,2)=ref_psd(j,2)*scale;
end
new_psd(:,1)=ref_psd(:,1);
try
assignin('base', New_PSD{i}, new_psd);
catch
warndlg('assignin error')
return;
end
out1=sprintf(' %s',New_PSD{i});
disp(out1);
x_label='Frequency (Hz)';
y_label='Accel (G^2/Hz)';
t_string=title2{i};
ppp=new_psd;
fmin=new_psd(1,1);
fmax=new_psd(end,1);
n=length(new_psd(:,1));
df=(fmax-fmin)/(n-1);
grms=sqrt(sum(new_psd(:,2))*df);
t_string=sprintf('%s Overall %7.3g GRMS',t_string,grms);
[fig_num,h2]=plot_loglog_function_h2(fig_num,x_label,y_label,t_string,ppp,fmin,fmax);
pname=sprintf('scaled_%s',FS1);
print(h2,pname,'-dmeta','-r300');
out1=sprintf(' %s.emf',pname');
disp(out1);
%%
end
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function get_table_data(hObject, eventdata, handles)
try
A=char(get(handles.uitable_data,'Data'));
N=get(handles.listbox_num,'Value');
k=1;
for i=1:N
t_string{i}=A(k,:); k=k+1;
t_string{i} = strtrim(t_string{i});
end
for i=1:N
Ref_PSD{i}=A(k,:); k=k+1;
Ref_PSD{i} = strtrim(Ref_PSD{i});
end
for i=1:N
New_SPL{i}=A(k,:); k=k+1;
New_SPL{i} = strtrim(New_SPL{i});
end
for i=1:N
New_PSD{i}=A(k,:); k=k+1;
New_PSD{i} = strtrim(New_PSD{i});
end
setappdata(0,'t_string',t_string);
setappdata(0,'Ref_PSD',Ref_PSD);
setappdata(0,'New_SPL',New_SPL);
setappdata(0,'New_PSD',New_PSD);
catch
warndlg('get table failed');
return;
end
% --- Executes on button press in pushbutton_return.
function pushbutton_return_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_return (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
delete(Barrett_method_multiple_SV);
% --- Executes on button press in pushbutton_save_model.
function pushbutton_save_model_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_save_model (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
num=get(handles.listbox_num,'Value');
Barrett_multiple_SV.num=num;
try
data=get(handles.uitable_data,'Data');
Barrett_multiple_SV.data=data;
catch
end
try
ref_spl=get(handles.edit_ref_spl,'String');
Barrett_multiple_SV.ref_spl=ref_spl;
catch
end
% % %
structnames = fieldnames(Barrett_multiple_SV, '-full'); % fields in the struct
% % %
[writefname, writepname] = uiputfile('*.mat','Save data as');
%%% writepfname = fullfile(writepname, writefname);
%%% pattern = '.mat';
%%% replacement = '';
%%% sname=regexprep(writefname,pattern,replacement);
elk=sprintf('%s%s',writepname,writefname);
try
save(elk, 'Barrett_multiple_SV');
catch
warndlg('Save error');
return;
end
%%% SSS=load(elk)
%%%%%%%%%%
%%%%%%%%%%
% Construct a questdlg with four options
choice = questdlg('Save Complete. Reset Workspace?', ...
'Options', ...
'Yes','No','No');
% Handle response
switch choice
case 'Yes'
%% disp([choice ' Reseting'])
%% pushbutton_reset_Callback(hObject, eventdata, handles)
appdata = get(0,'ApplicationData');
fnsx = fieldnames(appdata);
for ii = 1:numel(fnsx)
rmappdata(0,fnsx{ii});
end
end
% --- Executes on button press in pushbutton_load_model.
function pushbutton_load_model_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_load_model (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disp(' ref 1');
[filename, pathname] = uigetfile('*.mat');
NAME = [pathname,filename];
struct=load(NAME);
structnames = fieldnames(struct, '-full'); % fields in the struct
disp(' ref 2');
k=length(structnames);
for i=1:k
namevar=strcat('struct.',structnames{i});
value=eval(namevar);
assignin('base',structnames{i},value);
end
disp(' ref 3');
structnames
% struct
try
Barrett_multiple_SV=evalin('base','Barrett_multiple_SV');
catch
warndlg(' evalin failed ');
return;
end
Barrett_multiple_SV
try
data=Barrett_multiple_SV.data;
set(handles.uitable_data,'Data',data);
catch
end
try
num=Barrett_multiple_SV.num;
set(handles.listbox_num,'Value',num);
catch
end
try
ref_spl=Barrett_multiple_SV.data;
set(handles.edit_ref_spl,'String',ref_spl);
catch
end
% --- Executes on selection change in listbox_num.
function listbox_num_Callback(hObject, eventdata, handles)
% hObject handle to listbox_num (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns listbox_num contents as cell array
% contents{get(hObject,'Value')} returns selected item from listbox_num
Ncolumns=4;
Nrows=get(handles.listbox_num,'Value');
A=get(handles.uitable_data,'Data');
for i=1:Nrows
data_s{i,1}='';
data_s{i,2}='choose';
data_s{i,3}='choose';
data_s{i,4}='';
end
if(~isempty(A))
sz=size(A);
Arows=sz(1);
M=min([ Arows Nrows ]);
for i=1:M
for j=1:Ncolumns
data_s{i,j}=A{i,j};
end
end
end
sz=size(data_s);
if(sz(1)>Nrows)
data_s=data_s{1:Nrows,:};
end
set(handles.uitable_data,'Data',data_s);
% --- Executes during object creation, after setting all properties.
function listbox_num_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox_num (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox 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 edit_ref_spl_Callback(hObject, eventdata, handles)
% hObject handle to edit_ref_spl (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 edit_ref_spl as text
% str2double(get(hObject,'String')) returns contents of edit_ref_spl as a double
% --- Executes during object creation, after setting all properties.
function edit_ref_spl_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_ref_spl (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 pushbutton_load_data.
function pushbutton_load_data_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_load_data (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% [filename, pathname] = uigetfile('*.mat');
% NAME = [pathname,filename];
NAME='saturn_v_spl.mat';
struct=load(NAME);
structnames = fieldnames(struct, '-full'); % fields in the struct
k=length(structnames);
for i=1:k
namevar=strcat('struct.',structnames{i});
value=eval(namevar);
assignin('base',structnames{i},value);
end
msgbox('Load complete');
% --- Executes when selected cell(s) is changed in uitable_data.
function uitable_data_CellSelectionCallback(hObject, eventdata, handles)
% hObject handle to uitable_data (see GCBO)
% eventdata structure with the following fields (see MATLAB.UI.CONTROL.TABLE)
% Indices: row and column indices of the cell(s) currently selecteds
% handles structure with handles and user data (see GUIDATA)
%% disp('uitable_data_CellSelectionCallback');
% --------------------------------------------------------------------
function uitable_data_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to uitable_data (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%% disp('uitable_data_ButtonDownFcn');
% --- Executes when entered data in editable cell(s) in uitable_data.
function uitable_data_CellEditCallback(hObject, eventdata, handles)
% hObject handle to uitable_data (see GCBO)
% eventdata structure with the following fields (see MATLAB.UI.CONTROL.TABLE)
% 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)
%% disp('uitable_data_CellEditCallback');
Nrows=get(handles.listbox_num,'Value');
A=get(handles.uitable_data,'Data');
str0=getappdata(0,'str0');
title=getappdata(0,'title');
if(~isempty(A))
sz=size(A);
nrows=sz(1);
for i=1:nrows
k = strfind(A{i,2},'choose');
if(isempty(k))
try
n = find(contains(str0,A{i,2} ));
A{i,1}=title{n};
ss=sprintf('scaled_%s',A{i,2});
A{i,4}=ss;
catch
end
end
end
end
set(handles.uitable_data,'Data',A);
% --- Executes on button press in pushbutton_load_all_ref_PSD.
function pushbutton_load_all_ref_PSD_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_load_all_ref_PSD (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
str0=getappdata(0,'str0');
Nrows=length(str0);
Ncolumns=4;
set(handles.listbox_num,'Value',Nrows);
A=get(handles.uitable_data,'Data');
for i=1:Nrows
data_s{i,1}='';
data_s{i,2}=str0{i};
data_s{i,3}='choose';
data_s{i,4}='';
end
out1=sprintf('ref 1 %s %s',str0{1},data_s{i,2});
disp(out1);
set(handles.uitable_data,'Data',data_s);
uitable_data_CellEditCallback(hObject, eventdata, handles);