필터 지우기
필터 지우기

i have a martix A, i want missing numbers in the 2nd column as i explained? any help??

조회 수: 2 (최근 30일)
A =
1 3
1 5
1 6
1 8
1 10
2 4
2 8
2 9
3 1
3 3
3 5
3 7
3 9
i want output as ROWS starting with 1 = missing numbers are 2 ,4,7,9
ROWS starting with 2 = missing numbers are 1,2 ,3,5,6,7,10
ROWS starting with 1 = missing numbers are 2,4,6,8,10

채택된 답변

madhan ravi
madhan ravi 2019년 2월 5일
Alternative:
T=array2table(A);
fun=@(x) setdiff(min(A(:,1)):max(A(:,2)),x);
C=rowfun(fun,T,...
'GroupingVariable','A1',...
'OutputFormat','cell');
Result=[repelem(unique(A(:,1)),cellfun(@length,C)) [C{:}]']

추가 답변 (2개)

TADA
TADA 2019년 2월 5일
편집: TADA 2019년 2월 5일
granted you always have 1:3 in the first column and values between 1 and 10 in the second:
A = [1,3; 1,5; 1,6; 1,8; 1,10; 2,4; 2,8; 2,9; 3,1; 3,3; 3,5; 3,7; 3,9]; % this is your matrix
B = [repmat([1;2;3],10,1) repmat((1:10)', 3, 1)];
C = setdiff(B,A,'rows');
This is the output:
C =
1 1
1 2
1 4
1 7
1 9
2 1
2 2
2 3
2 5
2 6
2 7
2 10
3 2
3 4
3 6
3 8
3 10

madhan ravi
madhan ravi 2019년 2월 5일
편집: madhan ravi 2019년 2월 5일
The below works for n numbers in the first column:
Min=min(A(:,2));
Max=max(A(:,2));
[a,b,c]=unique(A(:,1));
B=diff(b.');
C=mat2cell(A(:,2),[B numel(c)-sum(B)],1);
R=cellfun(@(x) setdiff(Min:Max,x),C,'un',0);
Result=[repelem(a,cellfun(@length,R)) [R{:}]']
Gives:
Result =
1 1
1 2
1 4
1 7
1 9
2 1
2 2
2 3
2 5
2 6
2 7
2 10
3 2
3 4
3 6
3 8
3 10

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by