Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2013

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

Search the Archive

Re: Consecutive variables from matrix

  • To: mathgroup at smc.vnet.net
  • Subject: [mg129369] Re: Consecutive variables from matrix
  • From: Ray Koopman <koopman at sfu.ca>
  • Date: Tue, 8 Jan 2013 11:43:43 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net
  • References: <kcg5t1$rcn$1@smc.vnet.net>

On Jan 7, 8:04 pm, Jesse Pisel <jessepi... at gmail.com> wrote:
> I don't know if I am going about this problem the wrong way or if it is even possible to use this method. I am interested in assigning the different rows of a 4x4 matrix to variables d1-d4 and the first value of a different matrix to a variable t and using the variables in an if then statement. An example of what I am trying to do is:
>
> data1 = RandomReal[{0, 10}, {4, 4}]
> data2 = RandomReal[{0, 10}, {4, 4}]
> t = data2[[1, 1]]
> d1 = data1[[1, 1]]
> d2 = data1[[1, 2]]
> d3 = data1[[1, 3]]
> d4 = data1[[1, 4]]
> If[t < d1 \[And] t < d2 \[And] t < d3 \[And] t < d4, 0, 1]
>
> But what I want to do is run through the first row of values in the data2 with the first row of values from data1 without having to write out all the different possible combinations eg:
>
> data1 = RandomReal[{0, 10}, {4, 4}]
> data2 = RandomReal[{0, 10}, {4, 4}]
> t = data2[[1, 1]]
> d1 = data1[[1, 1]]
> d2 = data1[[1, 2]]
> d3 = data1[[1, 3]]
> d4 = data1[[1, 4]]
> If[t < d1 \[And] t < d2 \[And] t < d3 \[And] t < d4, 0, 1]
>
> data1 = RandomReal[{0, 10}, {4, 4}]
> data2 = RandomReal[{0, 10}, {4, 4}]
> t = data2[[1, 2]]
> d1 = data1[[1, 1]]
> d2 = data1[[1, 2]]
> d3 = data1[[1, 3]]
> d4 = data1[[1, 4]]
> If[t < d1 \[And] t < d2 \[And] t < d3 \[And] t < d4, 0, 1]
>
> and so on for all the different combinations without having to use brute force. So in review I would like to be able to assign variables d1,d2,d3,d4 to the values in the first row, compare to variable t assigned to the first then second then third and fourth entries of the other matrix and then move to the next row in both matrices. Essentially reassigning the variables d1,d2,d3,d4 and t as the notebook runs.
>
> Any ideas on how to accomplish this and have the output in matrix/list form would be much appreciated.
>
> Thanks

If you want to change data1 and/or data2 between checks,
which is what your sample code does, then

  UnitStep[ data2[[1,j]] - Min@data1[[1]] ]

will give 0 or 1 according as the j'th term in row 1 of data2
is or is not less than all the terms in row 1 of data1.

If you want to use the same data1 and data2 throughout then
this will give a vector in which each term will be 0 or 1
according as the corresponding term in row 1 of data2
is or is not less than all the terms in row 1 of data1.

  UnitStep[ data2[[1]] - Min@data1[[1]] ]



  • Prev by Date: Re: Vertical Scrollbars Unresponsive in Pane
  • Next by Date: Re: Attaching a notebook to a message
  • Previous by thread: Consecutive variables from matrix
  • Next by thread: Vertical Scrollbars Unresponsive in Pane