简体   繁体   中英

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? For example, if I have X=rand (5,5,2,3,6) and Y=[0;0;0;0;1]; , can I slice every 5*5 array along the other dimensions to solve it against Y ?

I solved it with the help of Bruno Luong and his multisolver found here . 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)]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM