how to preallocate large logical array

조회 수: 107 (최근 30일)
Michael
Michael 2012년 3월 13일
댓글: Image Analyst 2018년 6월 23일
Hi
I'm trying to pre-allocate a huge logical matrix but I can't work out how to do it without creating a normal matrix then converting it (this intermediate step uses too much memory).
I've been trying A = zeros(50,50,50,50,50, 'uint8'); Which works to create one from 0-255 but I can't find what to write in the quotes to make it logical rather than numeric, and suspect there may be some kind of trick that I'm missing.
Thanks Mike

채택된 답변

Image Analyst
Image Analyst 2012년 3월 13일
A = false(numRows, numCols); % Or can use true()

추가 답변 (2개)

James Tursa
James Tursa 2012년 3월 13일
Another alternative (assumes that all of the elements are filled in downstream):
A = uninit(numRows, numCols, 'logical');
You can find uninit on the FEX here:

Ingrid
Ingrid 2018년 6월 23일
I am not sure in which release it started working but at least in R2018a
A = zeros(50,50,50,50,50, 'logical');
works.
  댓글 수: 1
Image Analyst
Image Analyst 2018년 6월 23일
Or use false() as I suggested:
A = false(50, 50, 50, 50, 50);
It's a bit simpler and more direct.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by