fid1=fopen('shuju.txt','r');
[y1]=fscanf(fid1,'%d');
fclose(fid1); %读取txt文件,读取时是一行一行读的,所以需要把基数项的赋值给x,把偶数项的 赋值给y
x=[];
y=[];
k=length(y1);
for i=1:k
if (mod(i,2)==1)
x=[x,y1(i)]; % 基数项写入x
else
y=[y,y1(i)]; % 偶数项写入y,生成的x,y是行向量,如果需要列向量转置就可以了
end
end
fid = fopen('data.txt', 'r');
a=fscanf(fid,'%d,%d',[2,inf]);
a=a';
x=a(:,1);
y=a(:,2);
>> help varargin
VARARGIN Variable length input argument list.
Allows any number of arguments to a function. The variable
VARARGIN is a cell array containing the optional arguments to the
function. VARARGIN must be declared as the last input argument
and collects all the inputs from that point onwards. In the
declaration, VARARGIN must be lowercase (i.e., varargin).
For example, the function,
function myplot(x,varargin)
plot(x,varargin)
collects all the inputs starting with the second input into the
variable "varargin". MYPLOT uses the comma-separated list syntax
varargin to pass the optional parameters to plot. The call,
myplot(sin(0:.1:1),'color',[.5 .7 .3],'linestyle',':')
results in varargin being a 1-by-4 cell array containing the
values 'color', [.5 .7 .3], 'linestyle', and ':'.
See also varargout, nargin, nargout, inputname, function, lists, paren.
Reference page in Help browser
doc varargin