Removing entries of vector indexed by odd integer.

조회 수: 23 (최근 30일)
David . 2013년 9월 25일
So, in a question we've been asked to define a vector "x" which begins at 1.5 and ends at -3.5 with 101 entries in between without the use of any loops. So, I used linspace(1.4, -3.5, 101) to do this. However the next part of the question requires you to create a matrix "y" which corresponds to "x" only with the entries indexed by an odd integer removed. How can you do this without using a loop? Is there a function for it? Thanks.

채택된 답변

Leah 2013년 9월 25일
You just have to reference every other element of the vector you created.
x=linspace(1.4, -3.5, 101) ;
  댓글 수: 1
David 2013년 9월 25일
Will that not include elements 1 and 101 though, and they're odd indexes? Why wouldn't it be y = x(2:2:100);?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Matt J
Matt J 2013년 9월 25일
편집: Matt J 님. 2013년 9월 25일
x=linspace(1.4, -3.5, 101) ;
  댓글 수: 9
David 2013년 9월 25일
Brilliant! Thanks a million.

댓글을 달려면 로그인하십시오.


Help CenterFile Exchange에서 Functional Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by