modify data stream by equating odd position=0

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 日

0 投票

k = 10;
x = 1:k;
y = x;
y(1:2:end) = 0;
z = x;
z(2:2:end) = 0;

5 件のコメント

Soumili Sen
Soumili Sen 2020 年 10 月 11 日
woow.. it's awsome. Thnks a lot. And thanks for suggetion.
Ameer Hamza
Ameer Hamza 2020 年 10 月 11 日
I am glad to be of help!
Soumili Sen
Soumili Sen 2020 年 12 月 1 日
編集済み: Soumili Sen 2020 年 12 月 1 日
I have one query about this method
k = 10;
x = 1:k;
y = x;
y(1:2:end) = 0;
p=h1*y+80;
Here I don't want to use 2 lines to assign the value of y in this same logic. I want to get same value of y,within the expression of p(without writting previous two line).IS it possible?
Thanks in advance
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 件)

カテゴリ

ヘルプ センター および File ExchangeSystems of Nonlinear Equations についてさらに検索

質問済み:

2020 年 10 月 11 日

コメント済み:

2020 年 12 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by