📄 plothdf.m
字号:
'Callback',@DirSelectCallback);
uicontrol(ts_select_panel,'BackgroundColor',clr, 'Style', 'text', 'String','Select pressure tap numbers:',...
'HorizontalAlignment','left','Units','characters','Position',[2 Y0-btm_h-9 menu_w-4 1.5]);
uicontrol(ts_select_panel,'BackgroundColor',clr, 'Style', 'text', 'String','(ctrl-click or shift-click to select multiple)',...
'HorizontalAlignment','left','Units','characters','Position',[2 Y0-btm_h-10 menu_w-4 1.5]);
tap_listbox = uicontrol(ts_select_panel, 'Style', 'listbox', 'String',tap_num_cell,'Value',tap_sel,...
'Units','characters','Position',[2 Y0-btm_h-38 menu_w-4 28],'BackgroundColor','w','Enable','on',...
'Min',1,'Max',length(tap_num),'Callback',@UpdateTSPlot);
ts_save_button = uicontrol(ts_select_panel, 'Style','pushbutton','String','Save selected time series...',...
'Units','characters','Position',[menu_w/2-15 Y0-btm_h-41 30 2],...
'Callback',@SaveTS);
ts_menu_panel = uipanel('Parent',ts_fig,'BackgroundColor',clr,'Units','character','Position',[0 0 X0 btm_h]);
uicontrol(ts_menu_panel, 'Style','pushbutton','String','Photos of Building Model',...
'Units','characters','Position',[X0/8-toggle_w/2 0.5 toggle_w toggle_h],...
'Callback',@ImgButtonCallback);
uicontrol(ts_menu_panel, 'Style','pushbutton','String','Pressure Tap Locations',...
'Units','characters','Position',[X0*3/8-toggle_w/2 0.5 toggle_w toggle_h],...
'Callback',@TapButtonCallback);
uicontrol(ts_menu_panel, 'Style','togglebutton','String','Pressure Time Series','Value',1,'Enable','inactive',...
'BackgroundColor',.87*[1 1 1],'Units','characters','Position',[X0*5/8-toggle_w/2 0.5 toggle_w toggle_h]);
uicontrol(ts_menu_panel, 'Style','pushbutton','String','Close',...
'Units','characters','Position',[X0*7/8-toggle_w/2 0.5 toggle_w toggle_h],...
'Callback',@ExitCallback);
Cp = cpmatrix( HDF_full_filename, tap_ind);
if plot_img
UpdateImage;
end
UpdatePlot;
UpdateTSPlot;
set(fig,'Visible','off');
set(ts_fig,'Visible','off');
uiwait(img_fig);
function OrigCallback( src, event )
set( orig_radio, 'Enable', 'inactive');
set( scaled_radio, 'Value', 0, 'Enable', 'on')
UpdatePlot;
end
function ScaledCallback( src, event )
set( scaled_radio, 'Enable', 'inactive');
set( orig_radio, 'Value',0, 'Enable', 'on');
UpdatePlot;
end
function UpdatePlot( src, event)
axes(plot_axes);
cla reset;
if get(orig_radio,'Value')
% plot original tap coordinates:
plot3(tap_c_3d(:,3),tap_c_3d(:,4),tap_c_3d(:,5),'b.');
hold on;
% Plot wire frame between corners of building:
for i = 1:length(line_ends)
plot3([corners(line_ends(i,1),1) corners(line_ends(i,2),1)],...
[corners(line_ends(i,1),2) corners(line_ends(i,2),2)],...
[corners(line_ends(i,1),3) corners(line_ends(i,2),3)],'k-');
end
hold off;
xlabel('x-axis'); ylabel('y-axis'); zlabel('z-axis');
title('Original pressure tap coordinates');
h = gca;
set(h, 'DataAspectRatio',[1 1 1],'Projection','perspective');
% axis equal
axis vis3d
elseif get(scaled_radio,'Value')
% plot scaled tap coordinates:
plot3(scl_tap_c_3d(:,3),scl_tap_c_3d(:,4),scl_tap_c_3d(:,5),'b.');
hold on;
% Plot wire frame between corners of building:
for i = 1:length(line_ends)
plot3([scl_corners(line_ends(i,1),1) scl_corners(line_ends(i,2),1)],...
[scl_corners(line_ends(i,1),2) scl_corners(line_ends(i,2),2)],...
[scl_corners(line_ends(i,1),3) scl_corners(line_ends(i,2),3)],'k-');
end
hold off;
xlabel('x-axis'); ylabel('y-axis'); zlabel('z-axis');
title('Pressure tap coordinates scaled to match building dimensions');
h = gca;
set(h, 'DataAspectRatio',[1 1 1],'Projection','perspective');
% axis equal
axis vis3d
end
UpdateTapLabel;
end
function UpdateTapLabel( src, event)
tap_sel = get(tap_label_listbox,'Value');
axes(plot_axes);
if ishandle(tap_circle), delete(tap_circle); end
if ishandle(tap_label), delete(tap_label); end
hold on;
if get(orig_radio,'Value')
tap_circle = plot3(tap_c_3d(tap_sel,3),tap_c_3d(tap_sel,4),tap_c_3d(tap_sel,5),'ro','LineWidth',2);
tap_label = text(tap_c_3d(tap_sel,3),tap_c_3d(tap_sel,4),tap_c_3d(tap_sel,5),tap_label_cell(tap_sel));
elseif get(scaled_radio,'Value')
tap_circle = plot3(scl_tap_c_3d(tap_sel,3),scl_tap_c_3d(tap_sel,4),scl_tap_c_3d(tap_sel,5),'ro','LineWidth',2);
tap_label = text(scl_tap_c_3d(tap_sel,3),scl_tap_c_3d(tap_sel,4),scl_tap_c_3d(tap_sel,5),tap_label_cell(tap_sel));
end
hold off;
end
function UpdateImage( src, event)
axes(img_axes);
cla reset;
image(HDF_img(img_num).img);
set(img_axes,'XTickLabel','','YTickLabel','');
end
function ImgSelectCallback( src, event )
img_num = get(img_popup,'Value');
UpdateImage;
end
function DirSelectCallback( src, event )
q = get(dir_popup,'Value');
HDF_filename = [hdf_filename_root theta_a_str(q,:) '.HDF'];
HDF_full_filename = fullfile(HDF_pathname, HDF_filename);
Cp = cpmatrix( HDF_full_filename, tap_ind);
set(ts_plot_panel,'Title',['Time series of pressure coefficients (filename: ' HDF_filename '):']);
UpdateTSPlot;
end
function UpdateTSPlot( src, event )
tap_sel = get(tap_listbox,'Value');
axes(ts_plot_axes);
cla reset;
hold on;
n_s = size(Cp,2); % number of samples
for i=1:length(tap_sel)
plot(1:1:n_s,Cp(tap_sel,:));
end
hold off;
legend(tap_num_cell(tap_sel),'Location','EastOutside');
xlabel('Sample Number');
ylabel('Pressure coefficient');
end
function SaveTS( src, event )
TS_filename = ['PR_TS_' HDF_filename(1:end-4) '.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);
V_H = HDF_struct.Reference_Wind_Speed*HDF_struct.Roof_Height_Velocity_Ratio;
n_s = size(Cp,2); % number of samples
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]);
fprintf( fw, '%s\n',['Terrain Conditions: ' HDF_struct.Exposure_Name]);
fprintf( fw, '%s\n',['Model Length Scale: 1:' num2str(HDF_struct.Building_Scale)]);
fprintf( fw, '%s\n',['Wind Direction: ' theta_a_cell{q}]);
fprintf( fw, '%s\n',['Mean Wind Speeed at Eave Height: ' num2str(V_H) ' ft/s']);
fprintf( fw, '%s\n',['Sampling Frequency: ' num2str(f_s) ' Hz']);
fprintf( fw, '%s\n',['Number of samples: ' num2str(n_s)]);
fprintf( fw, '\n');
fprintf( fw, '%s\n','NOTE: The pressure coefficient time series below are referenced using the mean wind speed at eave height at');
fprintf( fw, '%s\n',' model scale (given above). An equivalent prototype-scale sampling frequency (which depends on the');
fprintf( fw, '%s\n',' prototype-scale wind speed of interest) can be obtained by multiplying the model-scale sampling frequency');
fprintf( fw, '%s\n',' (given above) by (L_M/L_P)*(V_P/V_M) -- where (L_M/L_P) is the model length scale given above; V_M is the');
fprintf( fw, '%s\n',' mean wind speed at eave height at model scale (given above); and V_P is the mean wind speed at eave height');
fprintf( fw, '%s\n',' at prototype scale.');
fprintf( fw, '\n');
ts_format = '%g';
fprintf( fw, '%s','Sample');
for i=1:length(tap_sel)
ts_format = [ts_format ',%g'];
fprintf( fw, ',%s', tap_num_cell{tap_sel(i)});
end
ts_format = [ts_format '\n'];
fprintf( fw, '\n');
fprintf( fw, ts_format, [1:1:n_s; Cp(tap_sel,:)]);
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;
TS_structure.terrain = HDF_struct.Exposure_Name;
TS_structure.length_scale = HDF_struct.Building_Scale;
TS_structure.length_scale_comment = 'Ratio of full-scale length to model length';
TS_structure.wind_dir = theta_a(q);
TS_structure.wind_dir_comment = 'Wind direction in degrees from reference axis';
TS_structure.V_H = V_H;
TS_structure.V_H_comment = 'Mean wind speed at eave height in ft/s';
TS_structure.f_s = f_s;
TS_structure.f_s_comment = 'Sampling frequency at model scale in Hz';
TS_structure.n_s = n_s;
TS_structure.n_s_comment = 'Number of samples in each time series';
TS_structure.TS_columns = tap_num_cell(tap_sel);
TS_structure.TS = Cp(tap_sel,:)';
TS_structure.TS_comment = 'Pressure coefficients referenced using mean wind speed at eave height';
try
save(TS_full_filename, 'TS_structure' );
catch
msgstr = lasterr;
err = errordlg(msgstr, 'Error saving time series'); uiwait(err);
figure(ts_fig); return;
end
end
figure(ts_fig);
end
function TapButtonCallback( src, event )
if strcmp(get(img_fig, 'Visible'),'on')
new_pos = get(img_fig,'Position');
if new_pos(3)<0.9*X0 | new_pos(3)>1.1*X0 | new_pos(4)<0.9*Y0 | new_pos(4)>1.1*Y0
new_pos = [Xc Yc X0 Y0];
end
set( fig, 'Visible','on','Units','characters','Position',new_pos);
set( img_fig, 'Visible', 'off','Units','characters','Position',new_pos);
elseif strcmp(get(ts_fig, 'Visible'),'on')
new_pos = get(ts_fig,'Position');
if new_pos(3)<0.9*X0 | new_pos(3)>1.1*X0 | new_pos(4)<0.9*Y0 | new_pos(4)>1.1*Y0
new_pos = [Xc Yc X0 Y0];
end
set( fig, 'Visible','on','Units','characters','Position',new_pos);
set( ts_fig, 'Visible', 'off','Units','characters','Position',new_pos);
tap_sel = get(tap_listbox,'Value');
if ~isempty(setxor(tap_sel,get(tap_label_listbox,'Value')))
set(tap_label_listbox,'Value',tap_sel);
end
UpdateTapLabel;
end
end
function ImgButtonCallback( src, event )
if strcmp(get(fig, 'Visible'),'on')
new_pos = get(fig,'Position');
if new_pos(3)<0.9*X0 | new_pos(3)>1.1*X0 | new_pos(4)<0.9*Y0 | new_pos(4)>1.1*Y0
new_pos = [Xc Yc X0 Y0];
end
set( img_fig, 'Visible','on','Units','characters','Position',new_pos);
set( fig, 'Visible', 'off','Units','characters','Position',new_pos);
elseif strcmp(get(ts_fig, 'Visible'),'on')
new_pos = get(ts_fig,'Position');
if new_pos(3)<0.9*X0 | new_pos(3)>1.1*X0 | new_pos(4)<0.9*Y0 | new_pos(4)>1.1*Y0
new_pos = [Xc Yc X0 Y0];
set(ts_fig,'Position',new_pos);
end
set( img_fig, 'Visible','on','Units','characters','Position',new_pos);
set( ts_fig, 'Visible', 'off','Units','characters','Position',new_pos);
end
end
function TSButtonCallback( src, event )
if strcmp(get(fig, 'Visible'),'on')
new_pos = get(fig,'Position');
if new_pos(3)<0.9*X0 | new_pos(3)>1.1*X0 | new_pos(4)<0.9*Y0 | new_pos(4)>1.1*Y0
new_pos = [Xc Yc X0 Y0];
end
set( ts_fig, 'Visible','on','Units','characters','Position',new_pos);
set( fig, 'Visible', 'off','Units','characters','Position',new_pos);
tap_sel = get(tap_label_listbox,'Value');
if ~isempty(setxor(tap_sel, get(tap_listbox,'Value')))
set(tap_listbox,'Value',tap_sel);
end
UpdateTSPlot;
elseif strcmp(get(img_fig, 'Visible'),'on')
new_pos = get(img_fig,'Position');
if new_pos(3)<0.9*X0 | new_pos(3)>1.1*X0 | new_pos(4)<0.9*Y0 | new_pos(4)>1.1*Y0
new_pos = [Xc Yc X0 Y0];
end
set( ts_fig, 'Visible','on','Units','characters','Position',new_pos);
set( img_fig, 'Visible', 'off','Units','characters','Position',new_pos);
end
end
function ExitCallback( src, event )
close(ts_fig)
close(img_fig);
close(fig);
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -