필터 지우기
필터 지우기

How can I perform the following operation in matrix

조회 수: 1 (최근 30일)
dani elias
dani elias 2020년 8월 23일
댓글: dani elias 2020년 8월 23일
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
Bruno Luong 2020년 8월 23일
편집: Bruno Luong 2020년 8월 23일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by