skipping numbers in a data

2 ビュー (過去 30 日間)
Eshovo Moses
Eshovo Moses 2020 年 7 月 9 日
コメント済み: Eshovo Moses 2020 年 7 月 10 日
Hi everyone.
I have been trying to write a MATLAB code to plot only some sequentially selected points in a data set.
For example, I have a data set of n=[1 2 3 4 5 6 7 8 9 10.......95 96 97 98 99 100]. but i am only intersted to select and plot every other 5 points...i.e
n=[1 5 10 15 20 25.................80 85 90 95 100 ].
please can someone help me out. I tried with the for loop, it seems not to work for me.
Thank you all for your kind reply
  2 件のコメント
Stephen23
Stephen23 2020 年 7 月 10 日
Your sampling is a bit odd: if you select "every other 5 points" like you write (i.e. with a step of 5) then you will get
n = [1,6,11,16,21...]
and the difference between each value is 5. But your example has inconsistent steps: the first step is 4, all the other steps are 5:
>> n = [1,5,10,15,20,25]; % your example n
>> diff(n)
ans = 4 5 5 5 5
Eshovo Moses
Eshovo Moses 2020 年 7 月 10 日
Thank you Stephen.... I think "the step of 5" in my explanation was misleading. I actually meant all the multiples of 5 with 1 inclusive. Anyway madhan ravi has given an excellent solution.

サインインしてコメントする。

採用された回答

madhan ravi
madhan ravi 2020 年 7 月 9 日
n = [1, 5:5:100]
  1 件のコメント
Eshovo Moses
Eshovo Moses 2020 年 7 月 10 日
This is awesome. I am learning this trick for the first time. Thank you so much madhan ravi

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Exploration についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by