バージョン 1.0.0 (4.76 KB) 作成者: Matt J
A more efficient substitute for ndgrid meant to help capitalize on implicit expansion.
ダウンロード: 39
更新 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:


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,


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!
バージョン 公開済み リリース ノート