📄 xyp1.m
字号:
% xyp1.m
% Scope: This MATLAB program plots a x-y graph for a selected column from
% an ASCII data file; manual scaling is available.
% Usage: xyp1
% Inputs: - the name of the ASCII input data file (with extension),
% - the selected x-axis column index,
% - the column number to be plotted,
% - title of the plot,
% - y-axis label,
% - x-axis label,
% - optional, new axes limits [xmin xmax ymin ymax].
% Outputs: - selected 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 plotted against x column data.
% If statistics is needed use xyp1s.
% Last update: 08/23/00
% Copyright (C) 1997-00 by LL Consulting. All Rights Reserved.
clear
close all
disp(' ');
fname = input('Specify the name of the input file (with extension) --> ','s');
hh = load(fname);
[npt,nmax] = size(hh);
if nmax <= 1
disp(' ');
disp('Error - XYP1; ASCII input file has less than 2 columns');
disp(' ');
return;
end
disp(' ');
nx = input('Enter the column used for x-axis --> ');
if ((nx <= nmax) & (nx >= 1)),
x = hh(1:npt,nx);
else
disp(' ');
disp('x-axis column is not in the range; check the selection ...');
disp(' ');
return;
end
yes = 'y';
answer = 'y';
disp(' ');
fignr = 0;
while (strcmp(answer,yes) == 1)
fignr = fignr + 1;
n = input('Enter the column number to be plotted --> ');
disp(' ');
if ( (n <= nmax) & (n ~= nx) & (n >= 1) ),
y = hh(1:npt,n);
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(' ');
figure(fignr)
plot(x,y),grid,...
title(aa), ylabel(bb),xlabel(cc)
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
fignr = fignr + 1;
figure(fignr)
plot(xnew,ynew), grid,...
axis([xmin xmax ymin ymax]),...
title(aa), ylabel(bb), xlabel(cc),...
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 XYP1 ');
disp(' ');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -