Memory problem when accessing and copying the 3D array elements by subscripts

I am trying to access/copy values from an image 3D array to another 3D array using the subcripts (rows and columns). I am trying to avoid the for loop. With for loop this works fine. The size of the rows and columns is 121020 x 1. But I am getting a memory error as below:
Requested 121020x121020x3 (40.9GB) array exceeds maximum array size preference. Creation of arrays greater than this limit may take a
long time and cause MATLAB to become unresponsive.
The code snippet is below
% Find boundary of the cylindrical projection
[row,col] = find(ximg > 0 & ximg <= xdim & yimg > 0 & yimg <= ydim);
out(row,col,:) = image(row,col,:);
Any help to make it without for loop is appreciated!

3 件のコメント

darova
darova 2021 年 8 月 2 日
What are sizes of xdim and image?
Preetham Manjunatha
Preetham Manjunatha 2021 年 8 月 2 日
Image size is 384 x 512 x 3. So xdim is 512 and ydim is 384.
darova
darova 2021 年 8 月 2 日
what is size of ximg?

サインインしてコメントする。

 採用された回答

Matt J
Matt J 2021 年 8 月 2 日
編集済み: Matt J 2021 年 8 月 2 日
The better way would be to avoid using find():
region=(ximg > 0 & ximg <= xdim & yimg > 0 & yimg <= ydim);
imtmp=reshape(image,[],size(image,3));
outtmp=reshape(out,[],size(out,3));
outtmp(region,:)=imtmp(region,:);
out(:)=outtmp(:); clear outtmp imtmp

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeEntering Commands についてさらに検索

製品

リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by