3维矩阵 [英] 3 dimensional matrices

查看:177
本文介绍了3维矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个3D 4×4×4矩阵,我认为它是圆形的(因此,行的第4个元素与第一个元素一起关闭,列和页面也是如此).

I have a 3D 4-by-4-by-4 matrix and I consider it circular (so a 4th element of row closes with the 1st and same goes for columns and pages).

我们知道在3D中每个点正好有26个邻居,可以表示为(i,j,k-1)(i,j,k + 1)等,但是我不确定如何使matlab知道点(1,1,1)的(i,j,k-1)邻居不是(1,1,0),而是(因为它是圆形的)(1,1,4)以及该点( 2,4,3)的邻居(i,j + 1,k)不是(2,5,3),而是(2,1,3).换句话说,我该怎么做?

we know that in 3D each point has exactly 26 neighbors which can be stated as (i, j, k-1) (i, j, k+1) etc. but I am not sure how to make matlab know that a (i,j, k-1) neighbor of a point (1,1,1) is not (1,1,0) but (as it is circular) (1,1,4) as well as that point (2,4,3)'s neighbor (i,j+1,k) is not (2,5,3) but (2,1,3). In other words HOW DO I MAKE IT CIRCULAR?

谢谢

推荐答案

MATLAB对此没有内置工具,但是在访问矩阵时可以使用mod(模数)函数来实现所需的效果.为了说明这一点,

MATLAB does not have built-in facilities for this, but you can use the mod (modulus) function when accessing your matrix to achieve the effect you want. To illustrate this on a vector:

v=[1 2 3];
i=5;
result=v(mod(i-1, length(v))+1);
% assigns 2 to 'result'

您可能需要编写一个封装圆形"矩阵访问的函数,以便只在一个地方进行索引计算.

You'll probably want to write a function that encapsulates the "circular" matrix access so that you have to do the index computations in only one place.

这篇关于3维矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆