Reputation:
suppose that i want to create following data matrix
for creating such type of matrix, i have already written code
function [ x ]=create_matrix1(b,l)
n = length(b);
m = n-l+1;
x = zeros(m,l);
for i=1:m
x(i,:)=b(i:i+l-1);
end;
end
but when we have a large data, then creating of such matrix became big problem, for instance if we generate data from matlab like this
load ampoutput2.mat
[m n]=size(y)
m =
500000
n =
1
if p=2000
then of course it will crush, computer will stop working, is there any iterated version which i can do for creating this matrix?thanks very much
Upvotes: 0
Views: 77
Reputation: 15867
the matrix can be efficiently created this way:
create_matrix2 = @(b, l) b(bsxfun(@plus, (1 : l), (0 : numel(b)-l)'));
Upvotes: 1
Reputation: 781
I think what you want is the hankel
function. But you may not want to explicitly construct the matrix, depending on what you want to do with it. You can multiply matrices of this type against vectors in O(N log N) time with some calls to flip
and by using the FFT.
Upvotes: 1