从Matrix 3D获得矩阵2D,并给定的第三维的给定选择与第一个维度相对应
我有:
a矩阵3D:a =(m,n,k)。
与第一个维度的每个索引相对应的第三维的选择数组。 idn =(m,1)(其中任何IDN的值是[1,k]中的随机整数。
我需要捕获2D矩阵B(m,n),其中所述的第三维是从相应的例如,
idn(1) = 1;
idn(2) = k;
idn(j) = k-1;
由于
B(1,:) = A(1,:,idn(1)) = A(1,:,1);
B(2,:) = A(2,:,idn(2)) = A(2,:,k);
B(j,:) = A(j,:,idn(j)) = A(j,:,k-1);
不是常数,因此
我也尝试了以下代码。
B = A(:,:,idn(:));
IDN 给我解决方案。
I have:
A matrix 3D: A = (m, n, k).
An array of choices for the third dimension corresponding to each index of the first dimension. idn = (m, 1) (wherein the value of any idn is a random integer in [1,k].
I need to capture the 2D matrix B (m,n) wherein the referred third dimension to A is taken from the corresponding choice. For example:
idn(1) = 1;
idn(2) = k;
idn(j) = k-1;
Then:
B(1,:) = A(1,:,idn(1)) = A(1,:,1);
B(2,:) = A(2,:,idn(2)) = A(2,:,k);
B(j,:) = A(j,:,idn(j)) = A(j,:,k-1);
Since idn is not constant, a simple squeeze
could not help.
I have also tried the below code, but it does not work either.
B = A(:,:,idn(:));
It is very much appreciated if anyone could give me a solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可以用
sub2ind
premute
,但是我是最简单的方法我可以想到的是使用 linearear indexing 手动手动:This could be done with
sub2ind
andpermute
, but the simplest way I can think of is using linear indexing manually: