필터 지우기
필터 지우기

modify data stream by equating odd position=0

조회 수: 3 (최근 30일)
Soumili Sen
Soumili Sen 2020년 10월 11일
댓글: Soumili Sen 2020년 12월 1일
Dear sir/Ma'am
I have a data x=[1 2 3 4 5.........k]. Now I want a new data y=[0 2 0 4 0 6........k] from 'x' i.e, in new data stream the odd position's value will be '0' of 'x',rest values will be remain same as 'x'.and also want z= new data stream the even position's value will be '0' of 'x'.
What will be the matlab code?

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 10월 11일
편집: Ameer Hamza 2020년 10월 11일
k = 10;
x = 1:k;
y = x;
y(1:2:end) = 0;
z = x;
z(2:2:end) = 0;
  댓글 수: 5
Ameer Hamza
Ameer Hamza 2020년 12월 1일
편집: Ameer Hamza 2020년 12월 1일
Following shows one way to decrease the number of lines
k = 10;
x = 1:k;
p = h1*x.*((-1).^(1:k)>0)+80
But it is obviously more complicated and less readible.
Soumili Sen
Soumili Sen 2020년 12월 1일
ok,thanks

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

추가 답변 (0개)

카테고리

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