matlab中用于计量经济学的trimr的用法是什么?3
发布网友
发布时间:2023-10-27 00:14
我来回答
共2个回答
热心网友
时间:2024-11-24 05:10
从一组数据中,提取出部分数据,生成一个新的矩阵matrix(多行数组)或向量vector(一行数组)。
例如,
z = trimr(x,n1,n2);
取一个矩阵x中,第一行以后(n1=1),倒数第二行以前的数据(n2=2),生成一个新矩阵。
>> x=[1 2 3; 4 5 6; 7 8 9; 10 11 12; 13 14 15]
x =
1 2 3
4 5 6
7 8 9
10 11 12
13 14 15
>> ret = trimr(x,1,2)
ret =
4 5 6
7 8 9
热心网友
时间:2024-11-24 05:11
这是这个函数的说明
function z = trimr(x,n1,n2)
% PURPOSE: return a matrix (or vector) x stripped of the specified rows.
% -----------------------------------------------------
% USAGE: z = trimr(x,n1,n2)
% where: x = input matrix (or vector) (n x k)
% n1 = first n1 rows to strip
% n2 = last n2 rows to strip
% NOTE: modeled after Gauss trimr function
% -----------------------------------------------------
% RETURNS: z = x(n1+1:n-n2,:)
% -----------------------------------------------------
% written by:
% James P. LeSage, Dept of Economics
% University of Toledo
% 2801 W. Bancroft St,
% Toledo, OH 43606
% jpl@jpl.econ.utoledo.e
[n junk] = size(x);
if (n1+n2) >= n;
error('Attempting to trim too much in trimr');
end;
h1 = n1+1;
h2 = n-n2;
z = x(h1:h2,:);