Farbod
Farbod

Reputation: 117

repeating a vector many times without repmat MATLAB

I have a vector with very large size in column format, I want to repeat this vector multiple times. the simple method that works for small arrays is repmat but I am running out of memory. I used bsxfun but still no success, MATLAB gives me an error of memory for using ones. any idea how to do that?

Here is the simple code (just for demonstration):

 t=linspace(0,1000,89759)';

 tt=repmat(t,1,length(t));

or using bsxfun:

 tt=bsxfun(@times,t, ones(length(t),length(t)));

Upvotes: 0

Views: 414

Answers (1)

bremen_matt
bremen_matt

Reputation: 7349

The problem here is simply too much data, it does not have to do with the repmat function itself. To verify that it is too much data, you can simply try creating a matrix of ones of that size with a clear workspace to reproduce the error. On my system, I get this error:

>> clear
>> a = ones(89759,89759)
Error using ones
Requested 89759x89759 (60.0GB) array exceeds maximum array size preference. Creation of arrays greater than
this limit may take a long time and cause MATLAB to become unresponsive. See array size limit or preference
panel for more information.

So you fundamentally need to reduce the amount of data you are handling.

Also, I should note that plots will hold onto references to the data, so even if you try plotting this "in chunks", then you will still run into the same problem. So again, you fundamentally need to reduce the amount of data you are handling.

Upvotes: 3

Related Questions