Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Perform an operation amongst three vectors if they are closer than 5% to each other

1 回表示 (過去 30 日間)
Konstantinos Tsitsilonis
Konstantinos Tsitsilonis 2017 年 12 月 30 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hi all,
I have three vectors as seen below:
%Construct Vectors
x = linspace(5,20,20)' ;
vec1 = 5*x + 10 ;
vec2 = 6.2*x + 11 ;
vec3 = 6.5*x + 11 ;
I want to create a code such that it can find the vectors that are closer to each other than 5% of some fixed value, take the average of any adjacent vectors that comply with the above condition, and return this as one vector. I want this code to be generalised for any number of n vectors, that is why it seems to be so tough for me.
My attempt to perform the above can be seen below:
vec_mat = sort([vec1, vec2, vec3], 2) ; %sort vectors in ascending order
vec_diff = diff(vec_mat, 1, 2) ; %difference between sorted vectors
%Find index of the vectors closer than 5% to each other
idx = vec_diff < 140 * 0.05 ;
At this point i get stuck. Having the indices between the vectors that comply with my desired condition, i struggle to find a way to proceed in order to find the actual vectors that these indices correspond to and to perform my desired operation.
Thanks for your help in advance,
KMT.
  3 件のコメント
Konstantinos Tsitsilonis
Konstantinos Tsitsilonis 2018 年 1 月 3 日
編集済み: Konstantinos Tsitsilonis 2018 年 1 月 3 日
Hi, thanks for your response. I have finally resolved the issue by finding the normalised distance between them.
How can I mark the question as resolved?
Sarah Mohamed
Sarah Mohamed 2018 年 1 月 3 日
Great! If you would like to share your solution so that others can view it, you can post it below in the 'Answers' section. Otherwise, you are all set

回答 (0 件)

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by