How to filter the following vector from multiple vectors?
3 ビュー (過去 30 日間)
古いコメントを表示
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
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
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 件のコメント
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
2022 年 5 月 19 日
Maybe:
V = MM(:, abs(MM(2, :)) < 32);
[~, index] = min(V(1, :));
W = V(:, index)
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!