Conditioning data to match dimensions
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hi, I have a data set which is 1 x 8. I have two other sets of data B and C which are 1 x 130. What I want to do is, compare the values of data set B with that of A to find the closest element. Once the index of this element of B is known, I want to read the corresponding element of that index from C. I want to do this with every element and create a new matrix based on elements from C and should be 1 x 8.
I was thinking along the lines of using a for loop and then using something like:
for f= 1:8;
tmp = abs(b-a(1,f));
[idx idx] = min(tmp) %index of closest value
%%more code needed
end
I am bit lost after that about how I can efficiently implement this. Any ideas?
Thanks
0 Commenti
Risposta accettata
Andrei Bobrov
il 4 Apr 2013
A = rand(10,1);
B = rand(130,1);
C = randi(500,130,1);
a1 = A(1:8);
[~,idx] = min(abs(bsxfun(@minus,B,a1.')));
out = C(idx);
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Matrices and Arrays in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!