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: [mg30966] Re: [mg30933] checking for a particular value in a matrix
  • From: Tomas Garza <tgarza01 at prodigy.net.mx>
  • Date: Fri, 28 Sep 2001 03:55:19 -0400 (EDT)
  • References: <200109270616.CAA01120@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

The following will yield True or False according to whether there is only
one 1 in row:

Count[row, x_Integer/; x ==1] == 1

Your second question I don't understand (you should perhaps use SetDelayed
(:=) instead of Set (=) in the definition of convert). I tried

In[1]:=
convert[{1,1}]
Out[1]=
3

In[2]:=
convert[{1,0,0,0}]
Out[2]=
8

which both seem to be Ok.

Tomas Garza
Mexico City
----- Original Message -----
From: "Au Han Bin" <auhb3 at cz3.nus.edu.sg>
To: mathgroup at smc.vnet.net
Subject: [mg30966] [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
>



  • Prev by Date: Stuck in a For Loop
  • Next by Date: Re: integer to string??
  • Previous by thread: checking for a particular value in a matrix
  • Next by thread: Re: checking for a particular value in a matrix