Question about selecting elements in a vektor

조회 수: 1 (최근 30일)
malik abdelli
malik abdelli 2023년 9월 18일
댓글: malik abdelli 2023년 9월 18일
Hi
i have a vektor that is 1x7200 long. i want to get the value at index 500 and then the following 1000 values after that index and write them into a Vektor.
As an exemple to make this easier to understand.
a = [780 465 983 125 756 429 143 23 51 47 86 95 47 85 55 44 77 99];
i want to get the value at index 5 wich is 756 and then i want the next 3 values after that and write them in a vektor b.
So b would look like this b = [756 429 143 23 ];
i know that b = a(5) gives me the value 756 but how do i get the other 3 values after that?
Thank you.

채택된 답변

Dyuman Joshi
Dyuman Joshi 2023년 9월 18일
편집: Dyuman Joshi 2023년 9월 18일
Similar to your previous question -
a = [780 465 983 125 756 429 143 23 51 47 86 95 47 85 55 44 77 99];
%Index
idx = 5;
%next values
n=3;
%Get the values of index and the next values -
b = a(idx:idx+n)
b = 1×4
756 429 143 23
I suggest you to take with the free introductory course MATLAB Onramp tutorial to learn the essentials of MATLAB.
  댓글 수: 1
malik abdelli
malik abdelli 2023년 9월 18일
i just got confused because i wrote b = a(idx : 3 ); but it gave me a blank vektor, i forgot that i need to type idx 2 times. but now it works.
Thanks again :)

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

추가 답변 (0개)

제품

Community Treasure Hunt

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

Start Hunting!

Translated by