Find lower query points compared to the Reference vector

2 次查看(过去 30 天)
Hi all, I have two vectors, one is "Beg_Data" which has 19 values and I have another reference vector "Beg_In_Ex" which contains 1239 values (Data attached). I am computing a new vector "End_Cycle" same size (19 values) that of "Beg_Data" vector based on the nearest neighbour search. I would like to achieve the results of "End_Cycle" values lower than that of corresponding values that of "Beg_Data". However, using the method that I have attempted I found some values are always higher than that of the "Beg_Data" values. As you can see I want the difference to be always positive (End_Cycle<Beg_Data). Any help in this regard is highly appreciated.
load data.mat;
End_Cycle = dsearchn(Beg_In_Ex',Beg_Data);
End_Cycle = Beg_In_Ex(End_Cycle)';
Start_Stop = [End_Cycle Beg_Data]
Start_Stop = 19×2
1.0e+06 * 0.0746 0.0761 0.2064 0.2047 0.2327 0.2346 0.4144 0.4130 0.5276 0.5263 0.6324 0.6329 0.8096 0.8088 0.9534 0.9518 0.9722 0.9702 0.9777 0.9760
Difference = Start_Stop(:,2)-Start_Stop(:,1)
Difference = 19×1
1.0e+03 * 1.4242 -1.6832 1.9540 -1.3347 -1.3141 0.4402 -0.7642 -1.6077 -2.0212 -1.6784
  3 个评论
Voss
Voss 2022-8-7
Just change the definition of idx(ii):
idx(ii) = find(Beg_In_Ex >= Beg_Data(ii),1);

请先登录,再进行评论。

采纳的回答

Voss
Voss 2022-8-6
load data.mat;
idx = zeros(size(Beg_Data));
for ii = 1:numel(Beg_Data)
idx(ii) = find(Beg_In_Ex <= Beg_Data(ii),1,'last');
end
End_Cycle = Beg_In_Ex(idx).';
Start_Stop = [End_Cycle Beg_Data]
Start_Stop = 19×2
1.0e+06 * 0.0746 0.0761 0.2016 0.2047 0.2327 0.2346 0.4108 0.4130 0.5245 0.5263 0.6324 0.6329 0.8071 0.8088 0.9495 0.9518 0.9676 0.9702 0.9732 0.9760
Difference = Start_Stop(:,2)-Start_Stop(:,1)
Difference = 19×1
1.0e+03 * 1.4242 3.0948 1.9540 2.2663 1.7939 0.4402 1.6808 2.2943 2.5998 2.8346

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息

产品


版本

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by