Removing elements from an Array
이전 댓글 표시
I have two arrays:
A = [0, 1]; and B = [0, 1, 3, 1, 4, 5, 6];
I want to compare the first element of A to the first 3 elements of B and the second element of A to the next 4 elements of B. If the elements of A are equal I delete it from B. So in simple:
if (A(1) == B(1:3))
delete A(1) from B
Similarly
if (A(2) == B(4:7))
delete A(2) from B
Is there any way I can do this without having to enter the indices in a hard coded manner?
So in the end B should have the following elements:
B = [1, 3, 4, 5, 6];
댓글 수: 3
Jan
2018년 6월 22일
The question is not clear. What if A(1) is 1? Then 1 is found in the first block of B. Should B be set to
[0, 3, 1, 4, 5, 6];
afterwards, or to
[0, 3, 4, 5, 6];
Or should the elements of B removed at the end only after the matching elements have been found?
So what are the wanted outputs for:
A = [0, 1]
B1 = [0, 1, 2, 0, 1, 2]
B2 = [0, 0, 0, 1, 2, 3]
B3 = [1, 1, 2, 1, 1, 2]
?
CharlesB
2018년 6월 22일
Jan
2018년 6월 22일
Is this the same problem as in your thread https://www.mathworks.com/matlabcentral/answers/406790-removing-elements-from-an-array-based-on-their-position-for-every-3-elements? Then it is solved there.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!