How to set a range in a matrix to zero?

조회 수: 7 (최근 30일)
toka55
toka55 2017년 11월 2일
댓글: KL 2018년 1월 24일
I have a matrix like:
A=[2 4 8 1 4 6]
I want to set everything to zero accept element 3-5.
The result should be
A=[0 0 8 1 4 0]
How can I do that?

채택된 답변

KL
KL 2017년 11월 2일
A([1:3-1 5+1:end]) = 0
  댓글 수: 3
Tan Chin Wee
Tan Chin Wee 2018년 1월 23일
hi what does +1 and -1 means?
KL
KL 2018년 1월 24일
the question is to set everything to zero accept element 3-5. So +1 and -1 captures the elements beyond these limits. In this example, 1 to 2 and 6 to the last element.

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

추가 답변 (1개)

KSSV
KSSV 2017년 11월 2일
A=[2 4 8 1 4 6] ;
B = zeros(size(A)) ;
B([3,5]) = A([3,5]) ;

카테고리

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