How to perform inverse between a page of a 3D matrix and a column vector without loops?

조회 수: 1 (최근 30일)
The matrix H looks like 9 x 2 x 14 and matrix A1 is 9 x1. I need to perform inversion between every page of H with A using mldivide so that output looks like 2 x 1 x14 matrix. No loops.
clear all;
close all;
load H.mat
load A1.mat

채택된 답변

Steven Lord
Steven Lord 2023년 1월 11일
Why do you insist to do this without looping? If you have been told "for loops in MATLAB are slow" that is not necessarily the truth anymore.
But in this particular case it is possible to use pagemldivide to accomplish this task.

추가 답변 (1개)

Kevin Holly
Kevin Holly 2023년 1월 11일
편집: Kevin Holly 2023년 1월 11일
load H.mat
load A1.mat
size(H)
ans = 1×3
9 2 14
size(A1)
ans = 1×2
9 1
answer = H.\A1;
size(answer)
ans = 1×3
9 2 14
  댓글 수: 3
Kevin Holly
Kevin Holly 2023년 1월 11일
Ah, I see. I misread the output. So, you need to vectorize this:
load H.mat
load A1.mat
size(H)
ans = 1×3
9 2 14
size(A1)
ans = 1×2
9 1
for ii = 1:size(H,3)
answer(:,:,ii) =H(:,:,ii)\A1;
end
size(answer)
ans = 1×3
2 1 14
Kalasagarreddi Kottakota
Kalasagarreddi Kottakota 2023년 1월 11일
Hi Kelly,
The output is correct, but I dont want to use a loop. Is there any possibility without looping?

댓글을 달려면 로그인하십시오.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by