Compare 2 time series, array and map to third.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
0 commentaires
Réponse acceptée
Adam Danz
le 28 Mai 2019
Modifié(e) : Adam Danz
le 28 Mai 2019
This should work for you. The last value of B is changed to -inf so that all values other than NaN will be greater than or equal to the last one.
B(end) = -inf;
idx_A = arrayfun(@(x)find(x>=B,1),A);
Result
idx_A =
1
3
3
5
5
*Assumes B is sorted in descending order as described by OP.
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Shifting and Sorting Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!