📄 computedif.m
字号:
end
if out_opt_struct.mult_pks
DIF_struct.X_max_obs_all = X_max_obs_all;
DIF_struct.X_min_obs_all = X_min_obs_all;
end
DIF_struct.X_max_obs = X_max_obs;
DIF_struct.X_min_obs = X_min_obs;
end
if out_opt_struct.est_pks
X_max_est_all = cat(2,X_max_est_a, X_max_est_b, X_max_est_c, X_max_est_d);
X_min_est_all = cat(2,X_min_est_a, X_min_est_b, X_min_est_c, X_min_est_d);
X_max_est = zeros(n_r,n_q,n_f);
X_min_est = zeros(n_r,n_q,n_f);
for i = 1:n_q
X_max_est(:,i,:)=mean(X_max_est_all(:,find(theta_all==theta(i)),:),2);
X_min_est(:,i,:)=mean(X_min_est_all(:,find(theta_all==theta(i)),:),2);
end
if out_opt_struct.mult_pks
DIF_struct.X_max_est_all = X_max_est_all;
DIF_struct.X_min_est_all = X_min_est_all;
end
DIF_struct.X_max_est = X_max_est;
DIF_struct.X_min_est = X_min_est;
end
if out_opt_struct.pk_loads
load_max_all = cat(3,load_max_a,load_max_b,load_max_c,load_max_d);
load_min_all = cat(3,load_min_a,load_min_b,load_min_c,load_min_d);
load_max = zeros(n_a,n_r,n_q,n_f);
load_min = zeros(n_a,n_r,n_q,n_f);
for i = 1:n_q
load_max(:,:,i,:) = mean(load_max_all(:,:,find(theta_all==theta(i)),:),3);
load_min(:,:,i,:) = mean(load_min_all(:,:,find(theta_all==theta(i)),:),3);
end
if out_opt_struct.mult_pks
DIF_struct.load_max_all = load_max_all;
DIF_struct.load_min_all = load_min_all;
end
DIF_struct.load_max = load_max;
DIF_struct.load_min = load_min;
end
function WaitBarCancel(src, event)
delete(h1);
err = errordlg('Analysis cancelled by user', 'Analysis cancelled');
uiwait(err); DIF_struct.error = 1;
end
% function WaitBarClose(src, event)
% DIF_struct.error = 1;
% delete(h1);
% end
function fig = TSplot
scrsz = get(0,'ScreenSize');
X0 = scrsz(3)*.05;
Y0 = scrsz(4)*.1;
dX = scrsz(3)*.9;
dY = scrsz(4)*.8;
fig = figure('Color',clr,'Position',[X0 Y0 dX dY],'NumberTitle','off','Name','Time Series Plots');
set( fig, 'Units', 'character');
Size = get( fig, 'Position');
X0 = Size(3);
Y0 = Size(4);
mw = 70; % menu width
Xp = X0-mw;
A = 5;
B = 13;
C = 7;
bx = 10; % plot border width in x-direction
by = 4; % plot border width in y-direction
plot_panel = uipanel('Parent',fig,'BackgroundColor',clr,'Units','character','Position',[0 0 Xp Y0],...
'FontSize',12,'FontWeight','bold','TitlePosition','centertop','Title','Time Series Plots');
hA = axes('Parent', plot_panel, 'Units', 'character','Position',[bx Y0/2+by Xp/2-2*bx Y0/2-2*by]);
hB = axes('Parent', plot_panel, 'Units', 'character','Position',[bx by Xp/2-2*bx Y0/2-2*by]);
hC = axes('Parent', plot_panel, 'Units', 'character','Position',[Xp/2+bx Y0/2+by Xp/2-2*bx Y0/2-2*by]);
hD = axes('Parent', plot_panel, 'Units', 'character','Position',[Xp/2+bx by Xp/2-2*bx Y0/2-2*by]);
file_panel = uipanel('Parent',fig,'BackgroundColor',clr,'Units','character','Position',[X0-mw Y0-A mw-1 A],...
'FontSize',12,'FontWeight','bold','TitlePosition','centertop','Title',['Current file (' num2str(i) ' of ' num2str(p) '):']);
select_panel = uipanel('Parent',fig,'BackgroundColor',clr,'Units','character','Position',[X0-mw Y0-(A+B) mw-1 B],...
'FontSize',12,'FontWeight','bold','TitlePosition','centertop','Title','Select time series to plot (and save):');
proceed_panel = uipanel('Parent',fig,'BackgroundColor',clr,'Units','character','Position',[X0-mw Y0-(A+B+C) mw-1 C],...
'FontSize',12,'FontWeight','bold','TitlePosition','centertop','Title','Analysis Options:');
% 'FontSize',12,'FontWeight','bold','BorderType','none');
% filename_txt = uicontrol(file_panel,'BackgroundColor',clr, 'Style', 'text',...
% 'String',['Current filename (file ' num2str(i) ' of ' num2str(p) '):'],...
% 'HorizontalAlignment','left','Units','characters','Position',[2 A-2 mw-4 1.5]);
filename_edit = uicontrol('Parent',file_panel,'BackgroundColor',clr,'Units','character','Position',[2 A-4 mw-6 1.5],...
'HorizontalAlignment','left','Style','edit','Enable','inactive','String',HDF_filename_i);
frame_txt = uicontrol(select_panel,'BackgroundColor',clr, 'Style', 'text', 'String','Select frame:',...
'HorizontalAlignment','left','Units','characters','Position',[2 B-4 mw-4 1.5]);
frame_popup = uicontrol(select_panel, 'Style', 'popupmenu', 'String',frame_label,'Value',1,...
'Units','characters','Position',[2 B-5.5 mw-4 1.5],'BackgroundColor','w','Callback',@UpdatePlots );
resp_txt = uicontrol(select_panel,'BackgroundColor',clr, 'Style', 'text', 'String','Select response:',...
'HorizontalAlignment','left','Units','characters','Position',[2 B-8 mw-4 1.5]);
resp_popup = uicontrol(select_panel, 'Style', 'popupmenu', 'String',resp_label,'Value',1,...
'Units','characters','Position',[2 B-9.5 mw-4 1.5],'BackgroundColor','w','Callback',@UpdatePlots );
save_button = uicontrol(select_panel, 'Style','pushbutton','String','Save selected time series as...',...
'Units','characters','Position',[2 B-12 45 1.5],'Callback',@SaveTS);
cont_button = uicontrol(proceed_panel, 'Style','pushbutton','String','Continue to next file',...
'Units','characters','Position',[0.5*(mw-1)-25-2 C-4 25 1.5],'Callback',@ClosePlot);
plot_chkbox = uicontrol(proceed_panel, 'Style','checkbox','String','Suppress further time series plots',...
'Value',0,'Units','characters','Position',[0.5*(mw-1)-25-2 C-6 40 1.5]);
cancel_button = uicontrol(proceed_panel, 'Style','pushbutton','String','Cancel analysis',...
'Units','characters','Position',[0.5*(mw-1)+2 C-4 25 1.5],'Callback',@CancelAnalysis);
UpdatePlots;
function UpdatePlots( src, event )
f = get(frame_popup,'Value');
r = get(resp_popup,'Value');
axes(hA);
plot([1:TS_struct(f).n_s],TS_struct(f).ts_a(r,:),'k-',...
TS_struct(f).max_sample_a(r), X_max_obs_a(r,i,f),'ro', TS_struct(f).min_sample_a(r), X_min_obs_a(r,i,f),'bo');
if out_opt_struct.est_pks
hold on; plot([1 TS_struct(f).n_s],[X_max_est_a(r,i,f) X_max_est_a(r,i,f)],'r-');
plot([1 TS_struct(f).n_s],[X_min_est_a(r,i,f) X_min_est_a(r,i,f)],'b-'); hold off;
end
title(['Wind direction A = ' num2str(theta_a(i))]);
xlabel('Sample number');
ylabel([resp_names{r} ' (' resp_units{r} ')']);
axes(hB);
plot([1:TS_struct(f).n_s],TS_struct(f).ts_b(r,:),'k-',...
TS_struct(f).max_sample_b(r), X_max_obs_b(r,i,f),'ro', TS_struct(f).min_sample_b(r), X_min_obs_b(r,i,f),'bo');
if out_opt_struct.est_pks
hold on; plot([1 TS_struct(f).n_s],[X_max_est_b(r,i,f) X_max_est_b(r,i,f)],'r-');
plot([1 TS_struct(f).n_s],[X_min_est_b(r,i,f) X_min_est_b(r,i,f)],'b-'); hold off;
end
title(['Wind direction B = ' num2str(theta_b(i))]);
xlabel('Sample number');
ylabel([resp_names{r} ' (' resp_units{r} ')']);
axes(hC);
plot([1:TS_struct(f).n_s],TS_struct(f).ts_c(r,:),'k-',...
TS_struct(f).max_sample_c(r), X_max_obs_c(r,i,f),'ro', TS_struct(f).min_sample_c(r), X_min_obs_c(r,i,f),'bo');
if out_opt_struct.est_pks
hold on; plot([1 TS_struct(f).n_s],[X_max_est_c(r,i,f) X_max_est_c(r,i,f)],'r-');
plot([1 TS_struct(f).n_s],[X_min_est_c(r,i,f) X_min_est_c(r,i,f)],'b-'); hold off;
end
title(['Wind direction C = ' num2str(theta_c(i))]);
xlabel('Sample number');
ylabel([resp_names{r} ' (' resp_units{r} ')']);
axes(hD);
plot([1:TS_struct(f).n_s],TS_struct(f).ts_d(r,:),'k-',...
TS_struct(f).max_sample_d(r), X_max_obs_d(r,i,f),'ro', TS_struct(f).min_sample_d(r), X_min_obs_d(r,i,f),'bo');
if out_opt_struct.est_pks
hold on; plot([1 TS_struct(f).n_s],[X_max_est_d(r,i,f) X_max_est_d(r,i,f)],'r-');
plot([1 TS_struct(f).n_s],[X_min_est_d(r,i,f) X_min_est_d(r,i,f)],'b-'); hold off;
end
title(['Wind direction D = ' num2str(theta_d(i))]);
xlabel('Sample number');
ylabel([resp_names{r} ' (' resp_units{r} ')']);
end
function SaveTS( src, event )
f = get(frame_popup,'Value');
r = get(resp_popup,'Value');
TS_filename = ['TS_' HDF_filename_i(1:end-4) '_f' num2str(f) 'r' num2str(r) '.csv'];
if exist('tmp_TS_path.mat','file'), load('tmp_TS_path'); end
if ~exist('TS_path','var') || ~isstr(TS_path), TS_path = ''; end
[TS_filename, TS_path, filetype_ind]= uiputfile({'*.csv','Comma delimited (*.csv)';...
'*.mat', 'Matlab MAT-files (*.mat)'},'Save time series as', fullfile(TS_path,TS_filename));
if filetype_ind==0
figure(fig); return;
end
save('tmp_TS_path','TS_path');
TS_full_filename = fullfile(TS_path, TS_filename);
if filetype_ind==1
fw = fopen( TS_full_filename, 'wt');
if fw==-1
err = errordlg('Unable to open specified file for writing: make sure that the file is not currently open.',...
'Error saving time series'); uiwait(err);
figure(fig); return;
end
fprintf( fw, '%s\n',['HDF pressure file: ' HDF_filename_i]);
fprintf( fw, '%s\n',frame_label{f});
fprintf( fw, '%s\n',[resp_label{r} ' (' resp_units{r} ')']);
fprintf( fw, '%s\n',['Number of samples: ' num2str(TS_struct(f).n_s)]);
fprintf( fw, '%s\n','Wind Dir A,Wind Dir B,Wind Dir C,Wind Dir D');
fprintf( fw, '%g,%g,%g,%g\n',[theta_a(i) theta_b(i) theta_c(i) theta_d(i)]);
fprintf( fw, '%s\n','Time Series A,Time Series B,Time Series C,Time Series D');
fprintf( fw, '%g,%g,%g,%g\n', [TS_struct(f).ts_a(r,:); TS_struct(f).ts_b(r,:); TS_struct(f).ts_c(r,:); TS_struct(f).ts_d(r,:)] );
status = fclose(fw);
if status==-1
err = errordlg('Unable to close specified file after writing.', 'Error saving time series'); uiwait(err);
figure(fig); return;
end
elseif filetype_ind==2
TS_structure.HDF_filename = HDF_filename_i;
TS_structure.frame_label = frame_label{f};
TS_structure.resp_label = [resp_label{r} ' (' resp_units{r} ')'];
TS_structure.n_s = TS_struct(f).n_s;
TS_structure.theta_a = theta_a(i);
TS_structure.theta_b = theta_b(i);
TS_structure.theta_c = theta_c(i);
TS_structure.theta_d = theta_d(i);
TS_structure.ts_a = TS_struct(f).ts_a(r,:);
TS_structure.ts_b = TS_struct(f).ts_b(r,:);
TS_structure.ts_c = TS_struct(f).ts_c(r,:);
TS_structure.ts_d = TS_struct(f).ts_d(r,:);
try
save(TS_full_filename, 'TS_structure' );
catch
msgstr = lasterr;
err = errordlg(msgstr, 'Error saving time series'); uiwait(err);
figure(fig); return;
end
end
figure(fig);
end
function ClosePlot( src, event )
if get(plot_chkbox,'Value')
out_opt_struct.ts_plot = 0;
end
delete(fig);
end
function CancelAnalysis( src, event )
DIF_struct.error = 1;
delete(fig);
end
end
end
%ok = writeDIFfile( DIF_struct, DIF_full_filename )
%
% h1 = figure;
% h2 = figure;
% for i = 1:n_r
% figure(h1)
% subplot(n_r,1,i)
% plot(wind_dir_360, alpha_pk1_360(i,:),'ko'); hold on;
% plot(wind_dir_list', abs(alpha_pk1(i,:)),'k+');
% plot(wind_dir_list_op', abs(alpha_pk1_op(i,:)),'k.');
% plot(wind_dir_360_S, alpha_pk1_360_S(i,:),'bo');
% plot(wind_dir_list_S', abs(alpha_pk1_S(i,:)),'b+');
% plot(wind_dir_list_S_op', abs(alpha_pk1_S_op(i,:)),'b.');
% plot(wind_dir_360, alpha_pk1_360_ave(i,:),'m.-');
% hold off;
% figure(h2)
% subplot(n_r,1,i)
% plot(wind_dir_360, alpha_pk2_360(i,:),'ko'); hold on;
% plot(wind_dir_list', abs(alpha_pk2(i,:)),'k+');
% plot(wind_dir_list_op', abs(alpha_pk2_op(i,:)),'k.');
% plot(wind_dir_360_S, alpha_pk2_360_S(i,:),'bo');
% plot(wind_dir_list_S', abs(alpha_pk2_S(i,:)),'b+');
% plot(wind_dir_list_S_op', abs(alpha_pk2_S_op(i,:)),'b.');
% plot(wind_dir_360, alpha_pk2_360_ave(i,:),'m.-');
% hold off;
%
% end
%
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -