# How to filter the following vector from multiple vectors?

11 visualizaciones (últimos 30 días)
M el 19 de Mayo de 2022
Editada: Jon el 19 de Mayo de 2022
How to filter the following vector from multiple vectors?
I want to do the following for each matrix stored in M
suppose each vector is named as the following in Matrix M: [deltaX
deltaY
1]
I want to filter the vector that satisfy the following conditions:
if abs(deltaY) is less than threshold for example 32
then select that vectors/vector
after that if there are more than selected vectors, filter them as the following:
select the vector that has the min deltaX
*The out should be 23 separated vectors each corrosponding to its matrix
##### 1 comentarioMostrar NingunoOcultar Ninguno
Jan el 19 de Mayo de 2022
Editada: Jan el 19 de Mayo de 2022
What does this mean: "suppose the each vector is named as the following in Matrix MM"?
Would it be impolite if I reply although I'm neither Matt J nor Star Strider?! Please avoid addressing specific persons in the forum except if you have really good reasons.

Iniciar sesión para comentar.

Jon el 19 de Mayo de 2022
Editada: Jon el 19 de Mayo de 2022
I think this does what you describe
% filter matrix mm
% parameters
threshold = 32
% extract the matrix out of the cell array MM
mm = MM{1}
% find all of the columns where the value in the second row is over
% threshold
result1 = mm(:,abs(mm(2,:))>threshold)
% now pick the one with the smallest value of "delta x" (first row)
[~,idx] = min(result1(1,:));
result2 = result1(:,idx)
For the calculation of result2, which pick the one with the minimum value in the first row, I wasn't sure from your description if you wanted the minimum of the actual values, or the minimum absolute value. I picked the minimum, so it is one with a negative value. You can modify the code accordingly.
##### 3 comentariosMostrar 2 comentarios más antiguosOcultar 2 comentarios más antiguos
Jon el 19 de Mayo de 2022
Editada: Jon el 19 de Mayo de 2022
% filter matrices in M.mat
% parameters
threshold = 32
% load the cell array of matrices to be filtered
% loop through matrices filtering each one
% accumulate results (selected column) in a matrix where each column is the
% selected column from the corresponding matrix in M
numFilter = numel(M); % number of matrices to be filtered
R = zeros(3,numFilter); % preallocate array to hold results
for k = 1:numFilter
% extract the kth matrix to be filtered
m = M{k};
% find all of the columns where the value in the second row is less than
% threshold
result1 = m(:,abs(m(2,:))<threshold);
% now pick the one with the smallest value of "delta x" (first row)
[~,idx] = min(result1(1,:));
% store the result
R(:,k) = result1(:,idx);
end

Iniciar sesión para comentar.

### Más respuestas (1)

Jan el 19 de Mayo de 2022
Maybe:
V = MM(:, abs(MM(2, :)) < 32);
[~, index] = min(V(1, :));
W = V(:, index)
##### 0 comentariosMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!