http://www.mathworks.com/matlabcentral/newsreader/view_thread/291973
MATLAB Central Newsreader  find complementary values
Feed for thread: find complementary values
enus
©19942015 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Mon, 20 Sep 2010 15:16:04 +0000
find complementary values
http://www.mathworks.com/matlabcentral/newsreader/view_thread/291973#780933
Norman
This may be quite simple but I seem to have a brain block. arrgh.<br>
<br>
I have a matrix of with numbers in the range between 1 and 100. The matrix does not contain all values between 1 and 100 and for some numbers there might be multiple instances. For example 0, 10, 11, 11, 15, ..., and 89.<br>
<br>
Is there a(n) (elegant) way to find those numbers between 1 and 100 that are not represented in the matrix? i.e., 19, 1214, ...,90100.<br>
<br>
Any help is welcome.<br>
<br>
Cheers,<br>
Norman

Mon, 20 Sep 2010 15:28:05 +0000
Re: find complementary values
http://www.mathworks.com/matlabcentral/newsreader/view_thread/291973#780937
Matt J
"Norman " <nteferle@gmail.com> wrote in message <i77trk$2ih$1@fred.mathworks.com>...<br>
> This may be quite simple but I seem to have a brain block. arrgh.<br>
> <br>
> I have a matrix of with numbers in the range between 1 and 100. The matrix does not contain all values between 1 and 100 and for some numbers there might be multiple instances. For example 0, 10, 11, 11, 15, ..., and 89.<br>
> <br>
> Is there a(n) (elegant) way to find those numbers between 1 and 100 that are not represented in the matrix? i.e., 19, 1214, ...,90100.<br>
<br>
TheSet=1:100;<br>
idx=ismember(TheSet,YourValues);<br>
Misising = TheSet(~idx),

Mon, 20 Sep 2010 15:30:22 +0000
Re: find complementary values
http://www.mathworks.com/matlabcentral/newsreader/view_thread/291973#780940
Wayne King
"Norman " <nteferle@gmail.com> wrote in message <i77trk$2ih$1@fred.mathworks.com>...<br>
> This may be quite simple but I seem to have a brain block. arrgh.<br>
> <br>
> I have a matrix of with numbers in the range between 1 and 100. The matrix does not contain all values between 1 and 100 and for some numbers there might be multiple instances. For example 0, 10, 11, 11, 15, ..., and 89.<br>
> <br>
> Is there a(n) (elegant) way to find those numbers between 1 and 100 that are not represented in the matrix? i.e., 19, 1214, ...,90100.<br>
> <br>
> Any help is welcome.<br>
> <br>
> Cheers,<br>
> Norman<br>
<br>
Hi Norman,<br>
<br>
help setdiff<br>
<br>
B = randsample(100,100,true); % requires Statistics Toolbox<br>
% samples 100 values with replacement from 1:100<br>
C = setdiff(1:100,B);<br>
<br>
Wayne

Mon, 20 Sep 2010 15:40:05 +0000
Re: find complementary values
http://www.mathworks.com/matlabcentral/newsreader/view_thread/291973#780944
someone
"Wayne King" <wmkingty@gmail.com> wrote in message <i77ume$q87$1@fred.mathworks.com>...<br>
> "Norman " <nteferle@gmail.com> wrote in message <i77trk$2ih$1@fred.mathworks.com>...<br>
> > This may be quite simple but I seem to have a brain block. arrgh.<br>
> > <br>
> > I have a matrix of with numbers in the range between 1 and 100. The matrix does not contain all values between 1 and 100 and for some numbers there might be multiple instances. For example 0, 10, 11, 11, 15, ..., and 89.<br>
> > <br>
> > Is there a(n) (elegant) way to find those numbers between 1 and 100 that are not represented in the matrix? i.e., 19, 1214, ...,90100.<br>
> > <br>
> > Any help is welcome.<br>
> > <br>
> > Cheers,<br>
> > Norman<br>
> <br>
> Hi Norman,<br>
> <br>
> help setdiff<br>
> <br>
> B = randsample(100,100,true); % requires Statistics Toolbox<br>
> % samples 100 values with replacement from 1:100<br>
> C = setdiff(1:100,B);<br>
> <br>
> Wayne<br>
<br>
% I don't think setdiff works the way you think it does:<br>
<br>
<br>
>> A = [0, 10, 11, 11, 15, 89];<br>
>> B = 0:100;<br>
>> c = setdiff(A, B)<br>
<br>
c =<br>
<br>
Empty matrix: 1by0

Mon, 20 Sep 2010 15:48:05 +0000
Re: find complementary values
http://www.mathworks.com/matlabcentral/newsreader/view_thread/291973#780949
Matt J
"someone" <someone@somewhere.net> wrote in message <i77v8l$546$1@fred.mathworks.com>...<br>
<br>
> % I don't think setdiff works the way you think it does:<br>
> <br>
> <br>
> >> A = [0, 10, 11, 11, 15, 89];<br>
> >> B = 0:100;<br>
> >> c = setdiff(A, B)<br>
> <br>
> c =<br>
> <br>
> Empty matrix: 1by0<br>
============<br>
<br>
It's because you have the input arguments interchanged.

Mon, 20 Sep 2010 15:53:43 +0000
Re: find complementary values
http://www.mathworks.com/matlabcentral/newsreader/view_thread/291973#780950
Walter Roberson
On 20/09/10 10:40 AM, someone wrote:<br>
> "Wayne King" <wmkingty@gmail.com> wrote in message<br>
<br>
>> help setdiff<br>
>><br>
>> B = randsample(100,100,true); % requires Statistics Toolbox<br>
>> % samples 100 values with replacement from 1:100<br>
>> C = setdiff(1:100,B);<br>
<br>
> % I don't think setdiff works the way you think it does:<br>
<br>
>>> A = [0, 10, 11, 11, 15, 89];<br>
>>> B = 0:100;<br>
>>> c = setdiff(A, B)<br>
><br>
> c =<br>
><br>
> Empty matrix: 1by0<br>
<br>
You have reversed the order of the parameters relative to what Wayne <br>
suggested. setdiff(A,B) finds the elements of A that are not in B. In <br>
your example, there are no elements of A that are not also in B, so the <br>
result is an empty matrix. In Wayne's example, the larger set is in the <br>
A position, so the result would be the values _not_ sampled.

Mon, 20 Sep 2010 17:25:10 +0000
Re: find complementary values
http://www.mathworks.com/matlabcentral/newsreader/view_thread/291973#780967
someone
Walter Roberson <roberson@hushmail.com> wrote in message <bsLlo.99878$st2.46575@newsfe09.iad>...<br>
> On 20/09/10 10:40 AM, someone wrote:<br>
> > "Wayne King" <wmkingty@gmail.com> wrote in message<br>
> <br>
> >> help setdiff<br>
> >><br>
> >> B = randsample(100,100,true); % requires Statistics Toolbox<br>
> >> % samples 100 values with replacement from 1:100<br>
> >> C = setdiff(1:100,B);<br>
> <br>
> > % I don't think setdiff works the way you think it does:<br>
> <br>
> >>> A = [0, 10, 11, 11, 15, 89];<br>
> >>> B = 0:100;<br>
> >>> c = setdiff(A, B)<br>
> ><br>
> > c =<br>
> ><br>
> > Empty matrix: 1by0<br>
> <br>
> You have reversed the order of the parameters relative to what Wayne <br>
> suggested. setdiff(A,B) finds the elements of A that are not in B. In <br>
> your example, there are no elements of A that are not also in B, so the <br>
> result is an empty matrix. In Wayne's example, the larger set is in the <br>
> A position, so the result would be the values _not_ sampled.<br>
<br>
OOPS<br>
<br>
That explains it!<br>
<br>
Thanks

Mon, 20 Sep 2010 20:06:04 +0000
Re: find complementary values
http://www.mathworks.com/matlabcentral/newsreader/view_thread/291973#781015
Roger Stafford
"Norman " <nteferle@gmail.com> wrote in message <i77trk$2ih$1@fred.mathworks.com>...<br>
> This may be quite simple but I seem to have a brain block. arrgh.<br>
> <br>
> I have a matrix of with numbers in the range between 1 and 100. The matrix does not contain all values between 1 and 100 and for some numbers there might be multiple instances. For example 0, 10, 11, 11, 15, ..., and 89.<br>
> <br>
> Is there a(n) (elegant) way to find those numbers between 1 and 100 that are not represented in the matrix? i.e., 19, 1214, ...,90100.<br>
> <br>
> Any help is welcome.<br>
> <br>
> Cheers,<br>
> Norman<br>
       <br>
To put the result in something like the missinginterval form you used, do the following. Let A be a row vector of your given numbers (chosen from among numbers 1 to 100).<br>
<br>
x = [0,sort(A),101];<br>
p = find(diff(x)>1);<br>
B = [x(p)+1;x(p+1)1];<br>
<br>
Each of the elements in the top row of B give the initial number of a missing interval and the corresponding number in the bottom row gives the end of that interval. For example if A = [80 44 46 44], you would get<br>
<br>
B = [ 1 45 47 81<br>
43 45 79 100]<br>
<br>
indicating that intervals 143, 4545, 4779, and 81100 are missing in A.<br>
<br>
Roger Stafford

Wed, 22 Sep 2010 12:22:04 +0000
Re: find complementary values
http://www.mathworks.com/matlabcentral/newsreader/view_thread/291973#781570
Norman
Many thanks to Matt and everyone else who helped finding a solution to this.<br>
Excellent!<br>
Norman<br>
<br>
<br>
"Matt J " <mattjacREMOVE@THISieee.spam> wrote in message <i77ui5$hoe$1@fred.mathworks.com>...<br>
> "Norman " <nteferle@gmail.com> wrote in message <i77trk$2ih$1@fred.mathworks.com>...<br>
> > This may be quite simple but I seem to have a brain block. arrgh.<br>
> > <br>
> > I have a matrix of with numbers in the range between 1 and 100. The matrix does not contain all values between 1 and 100 and for some numbers there might be multiple instances. For example 0, 10, 11, 11, 15, ..., and 89.<br>
> > <br>
> > Is there a(n) (elegant) way to find those numbers between 1 and 100 that are not represented in the matrix? i.e., 19, 1214, ...,90100.<br>
> <br>
> TheSet=1:100;<br>
> idx=ismember(TheSet,YourValues);<br>
> Misising = TheSet(~idx),

Wed, 22 Sep 2010 12:43:05 +0000
Re: find complementary values
http://www.mathworks.com/matlabcentral/newsreader/view_thread/291973#781575
Jos (10584)
"Norman " <nteferle@gmail.com> wrote in message <i77trk$2ih$1@fred.mathworks.com>...<br>
> This may be quite simple but I seem to have a brain block. arrgh.<br>
> <br>
> I have a matrix of with numbers in the range between 1 and 100. The matrix does not contain all values between 1 and 100 and for some numbers there might be multiple instances. For example 0, 10, 11, 11, 15, ..., and 89.<br>
> <br>
> Is there a(n) (elegant) way to find those numbers between 1 and 100 that are not represented in the matrix? i.e., 19, 1214, ...,90100.<br>
> <br>
> Any help is welcome.<br>
> <br>
> Cheers,<br>
> Norman<br>
<br>
For continuous integers the following indexing trick is likely to be faster than setdiff<br>
<br>
SomeNumbers = [2 4 6 4 3 9 6 2] % with repetitions<br>
MyRange = 1:10<br>
Result = MyRange % work on a copy<br>
Result(SomeNumbers) = [] % remove from set<br>
<br>
hth<br>
Jos