Dear sir/ma'am
I have a 3D matrix as
y(:,:1)=h(:,:,1)*x(:,:,1)+h(:,:,2)*x(:,:,2)+h(:,:,3)*x(:,:,3)+h(:,:,4)*x(:,:,4)
y(:,:2)=h(:,:,5)*x(:,:,1)+h(:,:,6)*x(:,:,2)+h(:,:,7)*x(:,:,3)+h(:,:,8)*x(:,:,4)
y(:,:3)=h(:,:,9)*x(:,:,1)+h(:,:,10)*x(:,:,2)+h(:,:,11)*x(:,:,3)+h(:,:,12)*x(:,:,4)
y(:,:1)=h(:,:,13)*x(:,:,1)+h(:,:,14)*x(:,:,2)+h(:,:,15)*x(:,:,3)+h(:,:,16)*x(:,:,4)
But I want to compute generic matlab code as a loop for this implementation such that I can operate any value of h,x,y matrix and reach the same result as above description.
Thank you.

 채택된 답변

Ameer Hamza
Ameer Hamza 2020년 5월 9일
편집: Ameer Hamza 2020년 5월 14일

0 개 추천

Something like this
h = rand(5, 5, 16);
x = rand(5, 5, 4);
y = zeros(size(x));
count = 1;
for i=1:size(x, 3)
for j=1:4
y(:,:,i) = y(:,:,i) + h(:,:,count)*x(:,:,j);
count = count + 1;
end
end

댓글 수: 7

anindita Roy
anindita Roy 2020년 5월 11일
Thank you for responding.
In this code I have understand about the multipliaction part for multiplication with 'h' and 'x' also it is working properly. But here I am not able to undertand that how the addition principle is working?
Ameer Hamza
Ameer Hamza 2020년 5월 11일
Oh! I missed the addition in my original code. Check the updated code. Now you can see the addition too.
anindita Roy
anindita Roy 2020년 5월 11일
Yah. I got it.
Thank you
Ameer Hamza
Ameer Hamza 2020년 5월 11일
I am glad to be of help.
anindita Roy
anindita Roy 2020년 5월 14일
Sorry for a small doubt. where we are using for loop 'j' in terms of 'y' ?
Ameer Hamza
Ameer Hamza 2020년 5월 14일
You are correct. I missed that. The 'j' should appear in the indexing of 'x'. Check the updated code.
anindita Roy
anindita Roy 2020년 5월 18일
thanks.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2020년 5월 9일

댓글:

2020년 5월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by