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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by