📄 xypc2.m
字号:
% xypc2.m
% Scope: This MATLAB program plots a x-y graph of the difference between
% two data columns from different data files against a selected
% data column from the first input file as x-axis; manual scaling
% is available. In addition, the plot can incorporate statistic
% related to the selected graph, i.e. mean, standard deviation and
% root mean square (rms).
% Usage: xypc2
% Inputs: - the name of the first ASCII data input file (with extension),
% - the name of the second ASCII data input file (with extension),
% - the selected x-axis column index,
% - the column number to be compared between data files,
% - title of the plot,
% - y-axis label,
% - x-axis label,
% - optional, new axes limits [xmin xmax ymin ymax].
% Outputs: - selected graph
% Remarks: The column used as x-axis is selected from the first input data
% file. The computed/listed statistics is for the selected range of
% the x-axis. The comparison can use the same file.
% External Matlab macros used: rms
% Last update: 08/23/00
% Copyright (C) 1997-00 by LL Consulting. All Rights Reserved.
clear
close all
disp(' ');
fname1 = input('Specify the name of the first input data file (with extension) --> ','s');
hh1 = load(fname1);
[npt1,nmax1] = size(hh1);
if nmax1 < 2
disp(' ');
error('Error - XYPC2; first input file has less than 2 columns');
disp(' ');
return
end
disp(' ');
fname2 = input('Specify the name of the second data file name (with extension) --> ','s');
hh2 = load(fname2);
[npt2,nmax2] = size(hh2);
if nmax2 < 2
disp(' ');
error('Error - XYPC2; second input file has less than 2 columns');
disp(' ');
return
end
disp(' ');
nmax = min(nmax1,nmax2);
npt = min(npt1,npt2);
index = input('Enter column number used as x-axis from first file --> ');
x = hh1(1:npt,index); % data from the first input file
yes = 'y';
answer = 'y';
fignr = 0;
while (strcmp(answer,yes) == 1)
fignr = fignr + 1;
disp(' ');
n1 = input('Enter the column number to be compared from first file --> ');
disp(' ');
n2 = input('Enter the column number to be compared from second file --> ');
if ( (n1 <= nmax1) & (n1 >= 1) & (n2 <= nmax2) & (n2 >= 1) ),
y1 = hh1(1:npt,n1);
y2 = hh2(1:npt,n2);
y = y1 - y2;
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];
disp(' ');
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)
plot(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 ... ');
disp(' ');
% Select manual scaling for both axes
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);
disp(' ');
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)
plot(x,y), 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('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');
end
disp(' ');
disp('End of the program XYPC2 ');
disp(' ');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -