modify data stream by equating odd position=0

3 次查看(过去 30 天)
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.

请先登录,再进行评论。

更多回答(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