Requested 250000x250000 (931.3GB) array exceeds maximum array size preference

1 vue (au cours des 30 derniers jours)
MAWE
MAWE le 15 Sep 2022
Commenté : MAWE le 16 Sep 2022
I have two vector x1 and x2 each of length 250,000X1 samples that I want to multiply them elementwise as below, but I get the error that array exceeds maximum array size preference. How can I solve this issue?
x1.*x2

Réponse acceptée

Voss
Voss le 15 Sep 2022
One of them is a 1x250000 row vector. You can transpose that one, or you can convert it (or both) to column vector(s):
x1(:).*x2(:) % 250000x1
  2 commentaires
John D'Errico
John D'Errico le 15 Sep 2022
For example:
x = 1:5;
y = [2 3 5 7 11]';
There, one is a row vector, the other a column vector.
If you just do this:
x.*y
then you get an array, which will overwhelm your memory for your vectors.
As @Voss correctly states (and I upvoted) you can make them both column vectors, using the colon index. Or you can transpose one of them.
My comment is to be careful using transpose if they are complex, since the ' operator is actually the CONJUGATE transpose. If all you want to do is change the shape of the vector from a column to a row, then use the .' operator. It does not perform a conjugate operation too.
x.*y.'
or
x(:).*y(:)
The nice thing about the latter is you know what the result will ALWAYS be: A column vector, of the correct size.
MAWE
MAWE le 16 Sep 2022
Thanks @Voss and @John D'Errico. It works perfectly fine now. Thanks for the clarification @John D'Errico

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by