how do I select every single element of matrix except middle

조회 수: 1 (최근 30일)
Vaultec
Vaultec 2015년 1월 16일
댓글: Niels 2015년 1월 20일
Say for example I have a 3 by 3 matrix
[1,2,3;4,5,6;7,8,9]
How do I select every element of the matrix except for the middle element?
  댓글 수: 2
David Young
David Young 2015년 1월 16일
What do you mean by "select"? In other words, what operation are you going to carry out on the non-central elements?
Vaultec
Vaultec 2015년 1월 16일
편집: Vaultec 2015년 1월 16일
Well any operation really, For example if multiply by 2 -1. Basically I want to be able to alter every single element except the central element.

댓글을 달려면 로그인하십시오.

답변 (1개)

Niels
Niels 2015년 1월 16일
편집: Niels 2015년 1월 16일
If I understand you correctly, you could do something like this:
A(A~=A(ceil(numel(A)/2)))
or
setdiff(A,A(ceil(numel(A)/2)))
Assuming you always have an odd number of elements these approaches should work.
Considering your edit, you could do it like this:
B = A([1:ceil(numel(A)/2)-1, ceil(numel(A)/2)+1:end]) * whatever;
Or, keeping it within A;
A([1:ceil(numel(A)/2)-1, ceil(numel(A)/2)+1:end]) = ...
A([1:ceil(numel(A)/2)-1, ceil(numel(A)/2)+1:end]) * whatever;
  댓글 수: 2
Vaultec
Vaultec 2015년 1월 16일
Sorry that wasnt what I was looking for. Is there anything similar to A(1:3,1:3) and someway to remove the middle element or set it to 0 as I simply want to do operations on the remaining 8 elements
Niels
Niels 2015년 1월 20일
Check the edit I did just 1 minute after you replied again. :)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by