Add a vector to a matrix if satisfies one condition

3 vues (au cours des 30 derniers jours)
Carlos Vanegas
Carlos Vanegas le 5 Déc 2019
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.

Réponses (1)

Bhaskar R
Bhaskar R le 5 Déc 2019
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

Catégories

En savoir plus sur Creating and Concatenating 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!

Translated by