Removing entries of vector indexed by odd integer.
10 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Leah
2013-9-25
You just have to reference every other element of the vector you created.
x=linspace(1.4, -3.5, 101) ;
y=x(1:2:end);
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!