MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: checking for a particular value in a matrix

  • To: mathgroup at smc.vnet.net
  • Subject: [mg30945] RE: [mg30933] checking for a particular value in a matrix
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.de>
  • Date: Fri, 28 Sep 2001 03:54:54 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

> -----Original Message-----
> From: Au Han Bin [mailto:auhb3 at cz3.nus.edu.sg]
To: mathgroup at smc.vnet.net
> Sent: Thursday, September 27, 2001 8:17 AM
> Subject: [mg30945] [mg30933] checking for a particular value in a matrix
> 
> 
> Hi, I am a programming newbie and I need advice on how to check that a
> table or matrix , for all nonzero entries in a given row, has only one
> entry of value 1.
> 
> 
> 
> i have another query on why the code below does not work, when i call
> convert{1,0,0,0} again, the results given are from an earlier 
> question,
> e.g. {1,1} is it initialised wrongly?
> 
> 
> Clear[a,convert];
> convert[a___] = Sum[a[[i]]*2^(Length[a]-i),{i,1,Length[a]}]
> 
> regards, thanks,
> 
> joshua
> 

Look what you have got
 
In[2]:= Clear[a, convert];
        convert[a___] = Sum[a[[i]]*2^(Length[a] - i), {i, 1, Length[a]}]
Out[3]= 0

In[4]:= ?? convert
>From In[4]:=
        "Global`convert"
>From In[4]:=
        convert[a___] = 0

Try
   convert[a_List] := Sum[a[[i]]*2^(Length[a] - i), {i, 1, Length[a]}]


As to your other question, see

In[5]:=
m = Table[Random[Integer, {0, 9}], {i, 5}, {j, 6}]
Out[5]=
{{5, 5, 6, 5, 1, 9},
 {2, 9, 9, 5, 1, 4},
 {8, 6, 3, 1, 0, 2}, {4, 2, 1, 3, 4, 
    2}, {1, 8, 7, 1, 3, 7}}
In[6]:=
Position[m, 1]
Out[6]=
{{1, 5}, {2, 5}, {3, 4}, {4, 3}, {5, 1}, {5, 4}}
In[7]:=
And @@ (Length[#] <= 1 &) /@ Split[First /@ Position[m, 1]]
Out[7]=
False



  • Prev by Date: Mathematica 4.0 installation problem
  • Next by Date: Re: Export table problem
  • Previous by thread: RE: checking for a particular value in a matrix
  • Next by thread: FileName and Shell Command