How to filter the following vector from multiple vectors?

7 vues (au cours des 30 derniers jours)
M
M le 19 Mai 2022
Modifié(e) : Jon le 19 Mai 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 commentaire
Jan
Jan le 19 Mai 2022
Modifié(e) : Jan le 19 Mai 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.

Connectez-vous pour commenter.

Réponse acceptée

Jon
Jon le 19 Mai 2022
Modifié(e) : Jon le 19 Mai 2022
I think this does what you describe
% filter matrix mm
% parameters
threshold = 32
% extract the matrix out of the cell array MM
load MM.mat
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 commentaires
M
M le 19 Mai 2022
@Jon, thank you so much.
Can you please help in iterating your code For all M matrix that I added to the question please.
Jon
Jon le 19 Mai 2022
Modifié(e) : Jon le 19 Mai 2022
% filter matrices in M.mat
% parameters
threshold = 32
% load the cell array of matrices to be filtered
load M.mat
% 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

Connectez-vous pour commenter.

Plus de réponses (1)

Jan
Jan le 19 Mai 2022
Maybe:
V = MM(:, abs(MM(2, :)) < 32);
[~, index] = min(V(1, :));
W = V(:, index)

Catégories

En savoir plus sur Resizing and Reshaping 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