Get array of elements based on occurrences of another vector
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Enrico Gambini
am 9 Sep. 2022
Beantwortet: Matt J
am 9 Sep. 2022
Hi guys!
Let's assume that you have 2 Nx1 arrays "y" and "x", is there a way to find all the elements of y corresponding to the unique elements of x?
E.g
y=[0;1;2;3;4];
x=[1;1;2;2;2];
%The results should be two vectors, one containing the elements [0;1] and the other one containing
%[2;3;4]
Thank you!
0 Kommentare
Akzeptierte Antwort
Torsten
am 9 Sep. 2022
y=[0;1;2;3;4];
x=[1;1;2;2;2];
z{1} = y(x==1);
z{2} = y(x==2);
z{1}
z{2}
0 Kommentare
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!