How to filter the following vector from multiple vectors?

조회 수: 12 (최근 30일)
M
M 2022년 5월 19일
편집: Jon 2022년 5월 19일
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
Jan
Jan 2022년 5월 19일
편집: Jan 2022년 5월 19일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Jon
Jon 2022년 5월 19일
편집: Jon 2022년 5월 19일
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
M
M 2022년 5월 19일
@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 2022년 5월 19일
편집: Jon 2022년 5월 19일
% 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

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jan
Jan 2022년 5월 19일
Maybe:
V = MM(:, abs(MM(2, :)) < 32);
[~, index] = min(V(1, :));
W = V(:, index)

카테고리

Help CenterFile Exchange에서 Matched Filter and Ambiguity Function에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by