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 ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by