How can I perform the following operation in matrix

1 vue (au cours des 30 derniers jours)
dani elias
dani elias le 23 Août 2020
Commenté : dani elias le 23 Août 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

Réponse acceptée

Bruno Luong
Bruno Luong le 23 Août 2020
Modifié(e) : Bruno Luong le 23 Août 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
  1 commentaire
dani elias
dani elias le 23 Août 2020
thank you, this is what i was looking for

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by