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.

 Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 9 Mai 2020
Bearbeitet: Ameer Hamza am 14 Mai 2020

0 Stimmen

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 Kommentare

anindita Roy
anindita Roy am 11 Mai 2020
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 am 11 Mai 2020
Oh! I missed the addition in my original code. Check the updated code. Now you can see the addition too.
anindita Roy
anindita Roy am 11 Mai 2020
Yah. I got it.
Thank you
Ameer Hamza
Ameer Hamza am 11 Mai 2020
I am glad to be of help.
anindita Roy
anindita Roy am 14 Mai 2020
Sorry for a small doubt. where we are using for loop 'j' in terms of 'y' ?
Ameer Hamza
Ameer Hamza am 14 Mai 2020
You are correct. I missed that. The 'j' should appear in the indexing of 'x'. Check the updated code.
anindita Roy
anindita Roy am 18 Mai 2020
thanks.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by