Select value with constant interval

6 次查看(过去 30 天)
Hi everyone, I need select values with constant interval from a certain column of a matrix. 3rd, 6th, 9th... like that. I must extract and create a new vector by them. I have not met any topic related to my problem. Can you help me?

回答(1 个)

Star Strider
Star Strider 2017-7-8
See the documentation on Matrix Indexing (link) and the colon (link) operator.
Example
M = randi(9, 10, 4); % Create Matrix
Col = 3; % Choose Column
Out = M(3:3:end, Col); % Selected Rows From Specified Column
  2 个评论
Anil Poyraz
Anil Poyraz 2017-7-8
Thanks for your answer, but I don't see an exact response to my problem. I also checked the documentation again, but couldn't see anything related to selection based on constant intervals. I think that learning how to select value by interval from vector does even help...
Les Beckham
Les Beckham 2017-7-8
Re-read the documentation on the colon operator (especially the second form of the Syntax examples). Star provided the correct answer and an example matching the example in your question. Perhaps if the last line of the example was written as follows it would clarify things:
Out = M(startIndex:interval:end, Col);

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by