필터 지우기
필터 지우기

How to eliminate the repeated number?

조회 수: 2 (최근 30일)
tabw
tabw 2014년 8월 13일
답변: Geoff Hayes 2014년 8월 13일
For example,
number= 1: 10;
t=[1 3 5 7];
What I want to keep is [2 4 6 7 10];
how to do that?
assuming t and number have different dimensions.
In short, I want number array to have no same digits of t.
Thanks

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 8월 13일
편집: Azzi Abdelmalek 2014년 8월 13일
number= 1: 10;
t=[1 3 5 7];
out=setdiff(number,t)

추가 답변 (1개)

Geoff Hayes
Geoff Hayes 2014년 8월 13일
tabw - consider using intersect. It will allow you to determine which values of t are in number, and then you can remove those common to both from number. Try the following
x = 1:10;
t = [1 3 5 7];
[common,indcsT,indcsX] = intersect(t,x)
% common is a vector of all values that are common to both t and x
% indcsT is a vector of indices into t of all common values
% indcsX is a vector of indices into x of all common values
% now remove the common elements from x
x(indcsX) = [];
The update x becomes
x =
2 4 6 8 9 10
It is slightly different from your example, but follows your instructions on wanting the first array to have no same digits as t.

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by