필터 지우기
필터 지우기

how to insert 1 in place of inf in a given array

조회 수: 1 (최근 30일)
anshuman mishra
anshuman mishra 2019년 7월 28일
댓글: Stephen23 2019년 7월 30일
given array :
Inf 4 2 2 4 Inf
i want my final output satisfy two conditions:
1. insert value 1 wherever Inf is encountered
2.insert value 1 wherever 2 or any number is encountered multiple times consequetively.
final output : 1 0 1 0 0 1
Edit: Thanks a lot,that worked like hot knife on butter :)
i've got another issue:I want to append 1 to start of every array
Ex-: a= [0 1 0 01]
my desired output= [1 0 1 0 0 1]

채택된 답변

Rik
Rik 2019년 7월 28일
편집: Rik 2019년 7월 28일
You can use the diff function and isinf to make this array.
final= [false diff(array)==0] | isinf(array) ;
  댓글 수: 7
Rik
Rik 2019년 7월 29일
The sum function can be used as a shorthand.

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

추가 답변 (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