I need help with this. How can I use indices to extract non consecutive numbers.

4 次查看(过去 30 天)
I am new to this forum. I am learning how to navigate the program through the MATLAB Onramp. I am trying to use indices to extract non consecutive numbers

回答(1 个)

Cris LaPierre
Cris LaPierre 2020-3-16
If you are stuck on a task in MATLAB Onramp, click the "Show Solution" link under the task.
  5 个评论
per isakson
per isakson 2020-5-18
编辑:per isakson 2020-5-18
>> density = 1:12; % sample data, assuming density is a vector
>> density([1,3,6]) %
ans =
1 3 6
>>
Stephen23
Stephen23 2020-5-18
"There is no indication of how to correctly extract non-consecutive numbers."
In the very first section on this page (entitled "Indexing Vectors") the third example is introduced with this exact text "Or the subscript can itself be another vector:" and then proceeds to give the example code:
v([1 5 6]) % Extract the first, fifth, and sixth elements
ans =
16 2 11
The first and fifth elements are clearly non-consecutive.
"I am assuming this should be one indice"
It is not clear what you mean by "one indice", but the example given on that page clearly shows one vector being used to obtain the non-consecutive elements, so you were thinking in the right direction.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by