ndgridVecs

버전 1.0.0 (4.76 KB) 작성자: Matt J
A more efficient substitute for ndgrid meant to help capitalize on implicit expansion.
다운로드 수: 42
업데이트 날짜: 2020/4/10

라이선스 보기

This submission contains a very simple bit of code, but one that is quite useful for taking advantage of Matlab's implicit expansion capabilities, introduced in R2016b. In the old days, one might have used ndgrid to do something like the following:

[I,J,K]=ndgrid(0:511);
X=I+J+K;

In the above, I,J,K, and X are all 512x512x512 arrays. This consumes a fair amount of memory, in fact 4 times the amount of memory consumed by the desired result X. Considerable CPU time is also spent allocating memory for and populating the grid arrays I, J, and K.

Then implicit expansion was introduced in R2016b allowing us to get the same result when I, J, and K are instead appropriately oriented "grid-vectors". The function ndgridVecs in this FEX submission is a tool to help generate such vectors. Just like ndgrid, it takes the desired grid vectors (in any orientation) as input, but reshapes/reorients them so that implicit expansion can be appropriately capitalized upon. With this function, the same array X as above can be generated as follows,

[Iv,Jv,Kv]=ndgridVecs(0:511);
X=Iv+Jv+Kv;

except that in this case the computation is based on vectors Iv, Jv, and Kv each of length 512. This is obviously much more efficient than the ndgrid method in which I,J,and K are 512x512x512 grid arrays.

See Examples tab for more detailed demonstration.

인용 양식

Matt J (2024). ndgridVecs (https://www.mathworks.com/matlabcentral/fileexchange/74956-ndgridvecs), MATLAB Central File Exchange. 검색 날짜: .

MATLAB 릴리스 호환 정보
개발 환경: R2018a
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!
버전 게시됨 릴리스 정보
1.0.0