Comparing two vectors with different dimensions
Ältere Kommentare anzeigen
Hello,
How can you compare two vectors with different number of elements? I am just trying to find the equal elements. Thanks!
Akzeptierte Antwort
Weitere Antworten (1)
Rohan Kale
am 19 Jun. 2012
1 Stimme
Let a and b be two arrays(or vectors). L=length(a), M=length(b).Suppose L>M, pad_zero=L-M; now b=[b zeros(1,pad_zero)]; c=a-b; now you can find the indices of the zero elements excluding the last pad_zero elements. These are your desired indices. Hope it helps.
2 Kommentare
the cyclist
am 19 Jun. 2012
Uh ... isn't it a lot easier to just use [c ia ib] = intersect(a,b)?
Rohan Kale
am 19 Jun. 2012
yes it is indeed, I was just trying out an alternative....
Kategorien
Mehr zu Logical 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!