How create a matrix that matches a condition in comparison with other matrix?
5 ビュー (過去 30 日間)
古いコメントを表示
The matrix A is given by several repeated values of A(:,1) positions with different A(:,2) values like:
clc;clear all
A=[
1 10
1 9
1 8
1 7
1 6
2 15
2 14
2 13
2 12
2 11
3 18
3 17
3 16
3 15
3 14
4 12
4 11
4 10
4 9
4 8];
scatter(A(:,1),A(:,2),'filled','r')
Represented by the following red dots:
The matrix B, represents 1 [X,Y] combination for each B(:,1) as:
%%
B=[
1 8
2 14
3 11
4 12];
hold on
scatter(B(:,1),B(:,2),'filled','b')
How can I eliminate all the values extrictly higher than any B(:,2) for each B(:,1) and keep only same or lower values getting a C matrix like:
%%
C=[
1 8
1 7
1 6
2 14
2 13
2 12
2 11
4 12
4 11
4 10
4 9
4 8];
scatter(C(:,1),C(:,2),'filled','g')
green dots represent the wanted points to keep.
0 件のコメント
採用された回答
Adam Danz
2020 年 12 月 2 日
A=[
1 10
1 9
1 8
1 7
1 6
2 15
2 14
2 13
2 12
2 11
3 18
3 17
3 16
3 15
3 14
4 12
4 11
4 10
4 9
4 8];
B=[
1 8
2 14
3 11
4 12];
idx = cell2mat(arrayfun(@(i){A(:,1)==B(i,1) & A(:,2)<= B(i,2)},1:size(B,1)));
[rowIdx,~] = find(idx);
C = A(rowIdx,:)
4 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!