Choosing Elements from a Vector.
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
malik abdelli
am 17 Sep. 2023
Kommentiert: malik abdelli
am 17 Sep. 2023
Hello,
Lets say I have a Vector A = [0 1 2 3 4 5 6 7 8 9] , i want to choose the number 5 for example and 2 elements after that.
So my vektor B would look like this B = [5 6 7].
How can i do this?
Thank you in advance.
0 Kommentare
Akzeptierte Antwort
Dyuman Joshi
am 17 Sep. 2023
A = [0 1 2 3 4 5 6 7 8 9]
%This finds all the elements in A that are equal to 5
idx = find(A==5)
%In case 5 appears more than once in A
%you want to find the first index, use
idx = find(A==5,1)
%Choosing the elements
B = A(idx:idx+2)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!