MATLAB Answers

update vector with nubers from another vector

2 views (last 30 days)
Karl Persson
Karl Persson on 28 Nov 2019
Commented: Karl Persson on 28 Nov 2019
Hi
I have a vector A = [ 2 4 6 10 15] and another vector B = [2.43 2.3 12 5.1]
How can I transform so that B = [2 2 10 6] with the help of A.

  2 Comments

the cyclist
the cyclist on 28 Nov 2019
Is the rule that for each value in B, you want the closest value in A?

Sign in to comment.

Accepted Answer

the cyclist
the cyclist on 28 Nov 2019
A = [ 2 4 6 10 15];
B = [2.43 2.3 12 5.1];
[~,idx] = min(abs(B'-A),[],2);
B = A(idx)

More Answers (0)

Sign in to answer this question.