📄 xpbar.m
字号:
% xpbar.m
% Scope: This MATLAB program plots a bar graph for a selected column from
% an ASCII data file against the selected x-axis column from the
% same ASCII file; manual scaling is available. In addition, the
% selected bar graph can incorporate statistics, i.e. mean, standard
% deviation and root mean square (rms).
% Usage: xpbar
% Inputs: - the name of the ASCII input data file,
% - the selected x-axis column index,
% - the column number to be bar-plotted,
% - title of the plot,
% - y-axis label,
% - x-axis label,
% - optional, new axes limits [xmin xmax ymin ymax].
% Outputs: - the selected bar-graph
% Remarks: The user can select the x-axis column; the other columns are used
% for y-axis coordinates. Each y column data (when selected) is
% independently bar-plotted against x column data.
% The computed/listed statistics is for the selected range of the
% specified bar-graph.
% External Matlab macros used: rms
% Last update: 04/09/00
% Copyright (C) 1997-00 by LL Consulting. All Rights Reserved.
clear
close all
disp(' ');
fname = input('Specify the name of the input data file --> ','s');
hh = load(fname);
[npt,nmax] = size(hh);
if nmax <= 1
error('Error - XPBAR ; ASCII input file has less than 2 columns');
end
disp(' ');
nx = input('Enter the column used for x-axis --> ');
if ((nx <= nmax) & (nx >= 1)),
x = hh(1:npt,nx);
else
disp('x-axis column is not in the range; check the selection ...');
return;
end
yes = 'y';
answer = 'y';
fignr = 0;
while (strcmp(answer,yes) == 1)
fignr = fignr + 1;
n = input('Enter the column number to be bar-plotted --> ');
disp(' ');
if ( (n <= nmax) & (n ~= nx) & (n >= 1) ),
y = hh(1:npt,n);
ymean = mean(y);
ystd = std(y);
yrms = rms(y);
temp1 = ['mean = ',num2str(ymean)];
temp2 = ['st.dev. = ',num2str(ystd)];
temp3 = ['rms = ',num2str(yrms)];
g = [temp1,' ; ',temp2,' ; ',temp3];
aa = input('Enter title of the plot : ','s');
bb = input('Enter Y label : ','s');
cc = input('Enter X label : ','s');
xmin = min(x);
xmax = max(x);
ymin = min(y);
ymax = max(y);
disp(' ');
disp('Place the text with statistics on the graph; ');
temp = input(' Press <Enter> or <Return> key to start ... ');
figure(fignr)
bar(x,y),grid,...
title(aa), ylabel(bb),xlabel(cc)
gtext(g) % mouse placement of the text on a graph
disp(' ');
temp = input('Press <Enter> or <Return> key to continue ... ');
% Select manual scaling for both axes
disp(' ');
manscaleq = input('Do you want manual scaling? (y/n)[n] ','s');
if (strcmp(manscaleq,yes) == 1),
redo_axes_limits = 1;
while (redo_axes_limits == 1)
fprintf('\nCurrent limits are : \n');
fprintf(' xmin = %14.7f \n',xmin);
fprintf(' xmax = %14.7f \n',xmax);
fprintf(' ymin = %14.7f \n',ymin);
fprintf(' ymax = %14.7f \n',ymax);
axes_limits = input('Enter axes limits [xmin xmax ymin ymax] : ');
xmin = axes_limits(1);
xmax = axes_limits(2);
ymin = axes_limits(3);
ymax = axes_limits(4);
fprintf('\nSelected limits are : \n');
fprintf(' xmin = %14.7f \n',xmin);
fprintf(' xmax = %14.7f \n',xmax);
fprintf(' ymin = %14.7f \n',ymin);
fprintf(' ymax = %14.7f \n',ymax);
disp(' ');
newlimq = input('Do you want to change axes limits? (y/n)[n] ','s');
if (strcmp(newlimq,yes) == 0),
redo_axes_limits = 0;
end
end
clear xnew;
clear ynew;
kk = 0;
for k = 1:npt
if ((x(k) >= xmin) & (x(k) <= xmax)),
kk = kk + 1;
xnew(kk) = x(k);
ynew(kk) = y(k);
end
end
xnew = xnew';
ynew = ynew';
ymean = mean(ynew);
ystd = std(ynew);
yrms = rms(ynew);
temp1 = ['mean = ',num2str(ymean)];
temp2 = ['st.dev. = ',num2str(ystd)];
temp3 = ['rms = ',num2str(yrms)];
g = [temp1,' ; ',temp2,' ; ',temp3];
disp(' ');
disp('Place the text with statistics on the graph; ');
temp = input(' Press <Enter> or <Return> key to start ... ');
fignr = fignr + 1;
figure(fignr)
bar(xnew,ynew), grid,...
axis([xmin xmax ymin ymax]),...
title(aa), ylabel(bb), xlabel(cc),...
gtext(g) % mouse placement of the text on a graph
disp(' ');
temp = input('Press <Enter> or <Return> key to continue ... ');
end
else
disp('y-axis column is not in the range; check the selection ...');
temp = ['The column range is: 1 to ',num2str(nmax)];
disp(temp);
end
disp(' ');
answer = input('Do you want another plot? (y/n)[n] ','s');
disp(' ');
end
disp('End of the program XPBAR ');
disp(' ');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -