[英]Can I use mldivide “\” on an nD matrix without using for loops in MATLAB?
Could I use mldivide
( \
) on an n-dimensional matrix in MATLAB without using for
loops?我可以在 MATLAB 中的 n 维矩阵上使用mldivide
( \
) 而不使用for
循环吗? For example, if I have X=rand (5,5,2,3,6)
and Y=[0;0;0;0;1];
例如,如果我有X=rand (5,5,2,3,6)
和Y=[0;0;0;0;1];
, can I slice every 5*5 array along the other dimensions to solve it against Y
? ,我可以沿其他维度对每个 5*5 数组进行切片以针对Y
解决它吗?
I solved it with the help of Bruno Luong and his multisolver found here .我在Bruno Luong和他的多重求解器的帮助下解决了这个问题。 The code below can solve any number of dimensions, considering the first two dimensions are of the same size.考虑到前两个维度的大小相同,下面的代码可以解决任意数量的维度。
M=rand(5,5,2,3,6);
RHS=[0;0;0;0;1];
sx = size(M);
sy = size(RHS);
dx = ndims(M);
MSOL=MultiSolver(reshape(M,sx(1),sx(2),[]),RHS);
MSOL = reshape(MSOL, [sx(2) sy(2) sx(3:dx)]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.