本文介绍了Meshgrid和ndgrid之间的实际区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于与ndgrid的pageIdx的讨论在此处越来越密集.我现在可以理解meshgrid而不是ndgrid -请详细说明可以使用它的实际示例.它实际上与meshgrid并不完全相同:值中有些奇怪的倒数,因此应该在何处使用它?

This discussion is getting dense here about pageIdx with ndgrid. I can understand now meshgrid but not ndgrid -- please elaborate with practical examples where it could be used. It is not really the same as meshgrid: some odd inversions in values so where it is meant to be used?

推荐答案

说您想知道数组的行/列/等索引.您可以使用meshgrid,但是它将首先输出列,然后输出行索引,这可能是错误的来源.

Say you want to know the row/column/etc indices of an array. You can use meshgrid for that, but it will output first the column, then the row indices, which can be a source of error.

您可以使用ndgrid代替meshgrid,这将按预期顺序给出索引,即

Instead of meshgrid, you can use ndgrid, which will give the indices in the expected order, i.e.

[rowIndices, colIndices] = ndgrid(1:size(array,1),1:size(array,2));

或者,对于3D

[rowIndices, colIndices, pageIndices] = ndgrid(1:size(array,1),1:size(array,2),1:size(array,3));

meshgrid对前两个索引的求反可以在处理绘图或图像处理工具箱功能的某些输出时提供帮助.

meshgrid's inversion of the first two indices can help when dealing with plotting, or with some of the output of Image Processing Toolbox functions.

但是,当您要计算4D高斯值时,唯一的选择是使用ndgrid:

However, when you want to calculate, say, the values of a 4D Gaussian, your only choice is to use ndgrid:

[xx,yy,zz,tt] = ndgrid(-3:0.1:3);
out = exp(-xx.^2-yy.^2-zz.^2-tt.^2);

这篇关于Meshgrid和ndgrid之间的实际区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 18:38