Add a vector to a matrix if satisfies one condition
3 ビュー (過去 30 日間)
古いコメントを表示
I have a random sorted matriz A of coordinates[x, y, z], sorted in the third column
A=
-3.7101 5.9258 9.9850
1.7114 1.9374 6.4446
0.4066 1.2890 3.9829
and another random vector B [x, y, z]
B=
-6.4932 3.3327 5.2881
I want to create a new matrix C, adding vector B to vector A (the position of the new vector does not matter):
C=
-3.7101 5.9258 9.9850
1.7114 1.9374 6.4446
0.4066 1.2890 3.9829
vector B--> -6.4932 3.3327 5.2881
BUT, I want to add the vector, if and only if the values in the third column satisfy the following condition:
6.44 - 1 > 5.2882 > 3.98 + 1
5.44 > 5.28 > 4.98
This means, I want to find in the matrix A the two closest values (in the third column) to B, and compare them in the condition. If the condition is accomplised, add the vector to the matrix. Thank you in advance I really appreciate your help.
I would like just to know how to find those two closest values to B(1,3)= in A and then test the condition.
0 件のコメント
回答 (1 件)
Bhaskar R
2019 年 12 月 5 日
col_3 = A(:, 3); % 3rd column of A
con = col_3(2)- 1> B(end) >col_3(end)+1; % your condition
if cond
C = [A;B]; % concatanate A and B
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!