Can I use mldivide “\” on a nD matrix without using for loops in Matlab?

조회 수: 2 (최근 30일)
Abdel-Rahman Ashraf
Abdel-Rahman Ashraf 2020년 5월 20일
편집: Abdel-Rahman Ashraf 2020년 5월 20일
Could I use mldivide (\) on an n-dimensional matrix 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? But for any N-D matrix.

답변 (1개)

Abdel-Rahman Ashraf
Abdel-Rahman Ashraf 2020년 5월 20일
편집: Abdel-Rahman Ashraf 2020년 5월 20일
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)]);

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by