How can I take the element of odd rows of an array (n rows, 1 column) and make a variable with all this elements?

4 ビュー (過去 30 日間)
Hallo all,
I want access to every element located in a odd row an make an array with all of them. For example:
A=(1:20)';
20 Rows and 1 column. So now I want in B every element from odd rows (1,3,5 so on).
For loop?

採用された回答

Arif Hoq
Arif Hoq 2022 年 3 月 21 日
編集済み: Arif Hoq 2022 年 3 月 21 日
you don't need a loop
A=(1:20)';
oddrow=A(1:2:end)
oddrow = 10×1
1 3 5 7 9 11 13 15 17 19
  2 件のコメント
Jose Rego
Jose Rego 2022 年 3 月 22 日
That´s right! Thanks Arif!
I was completely convinced that a for loop was the answer for my problem. I completely forgot this comand in Matlab.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by