Hi,
I have a random column vector A sorted from high to low. I have to map the position of its each entry on column vector B (again sorted high to low), and use that indexing to write a new function C.
Here's an example:
B = [3, 2.5, 2.0, 1.5, 1.0]';%% this BB column vector represents values from intervals: 0 to 1.0, 1.0 to 1.5, 1.5 to 2.0, 2.0 to 2.5, 2.5 to 3.0
A = [3.3, 2.4, 2.2, 1.3, 0.5]'idx_A = zeros(5,1); % ??? finds the position of A on the point intervals of B.
% I'm lookimg to use a formula or a faster way to get the following result.
idx_A(1,1) = 1; % as A(1,1) is greater than the 1st value of B.
idx_A(2,1) = 3; % as A(2,1) is greater than the 3rd value of B but smaller than 2nd value of B
idx_A(3,1) = 3; % as A(3,1) is greater than the 3rd value of B but smaller than 2nd value of B
idx_A(4,1) = 5; % as A(4,1) is greater than the 5th value of B but smaller than 4nd value of B
idx_A(5,1) = 5; % A(5,1) is lower than the least value of B so should be equal to the lowest value of B, which is 5.
% after finding idx_A, there is another column vector D which is used to find C as:
C = D(idx_A,1);display(D)
many thanks for your help.
Best Answer