how to concatenate vetcors
Ältere Kommentare anzeigen
I have 2 vectors v=[1 2 3 4 5 6 1 2 3] et k=[4 5 6 7 8 9].
I need to find the common part of the vectors which is [4 5 6] and replace it with a vector temp= [10 11 12].
The idea is to obtain at the end the vector cat= [1 2 3 10 11 12 1 2 3 7 8 9].
Please note that the vectors v and k don't have the same size.
Can anyone advise me with a method ?
Thanks in advance
1 Kommentar
" find the common part of the vectors"
Is there always one common subvector? How long can it be? Is there always a common subvector? Do you want all common subvectors, or just the longest one? Does the replacement vector always have the same length as the original subvector?
Akzeptierte Antwort
Weitere Antworten (1)
Andrei Bobrov
am 20 Jul. 2017
t1 = ismember(k,v);
v(ismember(v,k)) = temp;
out = [v,k(~t1)];
Kategorien
Mehr zu Characters and Strings finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!