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

4 views (last 30 days)
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
  2 Comments
Ameer Hamza
Ameer Hamza on 16 Mar 2020
Yes, you can easily extract them, so what is the problem? What forgot to mention the question.
Adeena Daley
Adeena Daley on 21 Mar 2020
Thanks for your response
How do you use indices to extract non consecutive numbers?

Sign in to comment.

Answers (1)

Cris LaPierre
Cris LaPierre on 16 Mar 2020
If you are stuck on a task in MATLAB Onramp, click the "Show Solution" link under the task.
  5 Comments
per isakson
per isakson on 18 May 2020
Edited: per isakson on 18 May 2020
>> density = 1:12; % sample data, assuming density is a vector
>> density([1,3,6]) %
ans =
1 3 6
>>
Stephen23
Stephen23 on 18 May 2020
"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.

Sign in to comment.

Tags

Products

Community Treasure Hunt

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

Start Hunting!