# How can I perform the following operation in matrix

2 views (last 30 days)
dani elias on 23 Aug 2020
Commented: dani elias on 23 Aug 2020
A=[2 3 4 5; 4 5 6 7; 3 4 5 6; 3 4 2 1] to get matrix B=[ 2 3 4 5; 4 20 18 7; 3 16 15 6; 3 4 2 1] the outer number remain as it was while the inner element is multiplied by the first row starting by the first element from the end. Matrix A is a square matrix of n dimensions. This is what I have tried so far
[m, n] = size(A); A= double(A);
for i=1:m
for j=1:n
if (j==1 && i==1)
B(i,j)= A(i,j);
elseif (i ==m && j==n)
B(i,j)= A(i,j);
else
B(i,j)= A(i,j+1) * A(i-1,n-j);
end
end
end

Bruno Luong on 23 Aug 2020
Edited: Bruno Luong on 23 Aug 2020
If I understand correctly
>> A=[2 3 4 5; 4 5 6 7; 3 4 5 6; 3 4 2 1]
A =
2 3 4 5
4 5 6 7
3 4 5 6
3 4 2 1
>> B=A
B =
2 3 4 5
4 5 6 7
3 4 5 6
3 4 2 1
>> B(2:end-1,2:end-1)=B(2:end-1,2:end-1).*B(1,end-1:-1:2)
B =
2 3 4 5
4 20 18 7
3 16 15 6
3 4 2 1
dani elias on 23 Aug 2020
thank you, this is what i was looking for

### Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by