Thread Subject: matrix generation

Subject: matrix generation

From: jack j

Date: 8 Nov, 2009 17:17:03

Message: 1 of 12

Hi,
I want to generate a 6x4 matrix of positive integers(max value:50) such that the difference between the 3rd element and 1st element in each row is 2 and difference of 2nd and 4th row element in all rows is 3.
Any help?

Subject: matrix generation

From: dpb

Date: 8 Nov, 2009 17:25:14

Message: 2 of 12

jack j wrote:
> Hi, I want to generate a 6x4 matrix of positive integers(max
> value:50) such that the difference between the 3rd element and 1st
> element in each row is 2 and difference of 2nd and 4th row element in
> all rows is 3. Any help?

Generate (say) first and second columns then add 2 and 3, respectively.
    You can ensure the condition by either rejecting greater>50 values
and regenerating that pair or restrict the original rng range to <48 so
sum can exceed 50.

--

Subject: matrix generation

From: Miroslav Balda

Date: 8 Nov, 2009 17:39:02

Message: 3 of 12

"jack j" <12mailjack@gmail.com> wrote in message <hd6uef$j43$1@fred.mathworks.com>...
> Hi,
> I want to generate a 6x4 matrix of positive integers(max value:50) such that the difference between the 3rd element and 1st element in each row is 2 and difference of 2nd and 4th row element in all rows is 3.
> Any help?

Hi,

Does it fit you?

% jack.m 2009-11-08
%%%%%%%%%%%%
A = zeros(6,4);
A(:,1) = ceil(48*rand(6,1));
A(:,3) = A(:,1)+2;
A(:,4) = ceil(47*rand(6,1)+3);
A(:,2) = A(:,4)-3

Mira

Subject: matrix generation

From: jack j

Date: 8 Nov, 2009 17:53:01

Message: 4 of 12

dpb <none@non.net> wrote in message <hd6utr$jgr$2@news.eternal-september.org>...
> jack j wrote:
> > Hi, I want to generate a 6x4 matrix of positive integers(max
> > value:50) such that the difference between the 3rd element and 1st
> > element in each row is 2 and difference of 2nd and 4th row element in
> > all rows is 3. Any help?
>
> Generate (say) first and second columns then add 2 and 3, respectively.
> You can ensure the condition by either rejecting greater>50 values
> and regenerating that pair or restrict the original rng range to <48 so
> sum can exceed 50.
>
> --

Did u mean a random number generation in a 'for' loop or a 6x2 random matrix generation and then a concatenation?

Subject: matrix generation

From: jack j

Date: 8 Nov, 2009 17:59:02

Message: 5 of 12

"Miroslav Balda" <miroslav.nospam@balda.cz> wrote in message <hd6vnm$7u3$1@fred.mathworks.com>...
> "jack j" <12mailjack@gmail.com> wrote in message <hd6uef$j43$1@fred.mathworks.com>...
> > Hi,
> > I want to generate a 6x4 matrix of positive integers(max value:50) such that the difference between the 3rd element and 1st element in each row is 2 and difference of 2nd and 4th row element in all rows is 3.
> > Any help?
>
> Hi,
>
> Does it fit you?
>
> % jack.m 2009-11-08
> %%%%%%%%%%%%
> A = zeros(6,4);
> A(:,1) = ceil(48*rand(6,1));
> A(:,3) = A(:,1)+2;
> A(:,4) = ceil(47*rand(6,1)+3);
> A(:,2) = A(:,4)-3
>
> Mira

Thankx Mira, it works....and thanks dpb......

Subject: matrix generation

From: dpb

Date: 8 Nov, 2009 18:10:24

Message: 6 of 12

jack j wrote:
> "Miroslav Balda" <miroslav.nospam@balda.cz> wrote in message <hd6vnm$7u3$1@fred.mathworks.com>...
>> "jack j" <12mailjack@gmail.com> wrote in message <hd6uef$j43$1@fred.mathworks.com>...
>>> Hi,
>>> I want to generate a 6x4 matrix of positive integers(max value:50) such that the difference between the 3rd element and 1st element in each row is 2 and difference of 2nd and 4th row element in all rows is 3.
>>> Any help?
>> Hi,
>>
>> Does it fit you?
>>
>> % jack.m 2009-11-08
>> %%%%%%%%%%%%
>> A = zeros(6,4);
>> A(:,1) = ceil(48*rand(6,1));
>> A(:,3) = A(:,1)+2;
>> A(:,4) = ceil(47*rand(6,1)+3);
>> A(:,2) = A(:,4)-3
>>
>> Mira
>
> Thankx Mira, it works....and thanks dpb......

Yes, precisely what I suggested altho he chose 1 and 4 as the two
independent and did a little finer pruning on the upper bounds than a
single limit.

--

Subject: matrix generation

From: jack j

Date: 8 Nov, 2009 18:37:01

Message: 7 of 12

dpb <none@non.net> wrote in message <hd71ii$9sb$1@news.eternal-september.org>...
> jack j wrote:
> > "Miroslav Balda" <miroslav.nospam@balda.cz> wrote in message <hd6vnm$7u3$1@fred.mathworks.com>...
> >> "jack j" <12mailjack@gmail.com> wrote in message <hd6uef$j43$1@fred.mathworks.com>...
> >>> Hi,
> >>> I want to generate a 6x4 matrix of positive integers(max value:50) such that the difference between the 3rd element and 1st element in each row is 2 and difference of 2nd and 4th row element in all rows is 3.
> >>> Any help?
> >> Hi,
> >>
> >> Does it fit you?
> >>
> >> % jack.m 2009-11-08
> >> %%%%%%%%%%%%
> >> A = zeros(6,4);
> >> A(:,1) = ceil(48*rand(6,1));
> >> A(:,3) = A(:,1)+2;
> >> A(:,4) = ceil(47*rand(6,1)+3);
> >> A(:,2) = A(:,4)-3
> >>
> >> Mira
> >
> > Thankx Mira, it works....and thanks dpb......
>
> Yes, precisely what I suggested altho he chose 1 and 4 as the two
> independent and did a little finer pruning on the upper bounds than a
> single limit.
>
> --

But what if the condition is something like " (1st column element-2nd column element)+(3rd column element-4th column element)"for all rows should be equal to x???

In this case will such a defn work out?

Subject: matrix generation

From: jack j

Date: 8 Nov, 2009 19:05:05

Message: 8 of 12


> But what if the condition is something like " (1st column element-2nd column element)+(3rd column element-4th column element)"for all rows should be equal to x???
>
> In this case will such a defn work out?

If the condition is "(1st column element-2nd column element)+(3rd column element-4th column element)" should be a number greater than 'x', then also I doubt whether such a column by column definition will work.

Please help.....

Subject: matrix generation

From: dpb

Date: 8 Nov, 2009 19:09:16

Message: 9 of 12

jack j wrote:
...
> But what if the condition is something like " (1st column element-2nd
> column element)+(3rd column element-4th column element)"for all rows
> should be equal to x???
>
> In this case will such a defn work out?

Possibly depending on the size of the selection pool and value of x.
The rudimentary case for the above would be generate three independently
and solve for the fourth as the parentheses make no difference
numerically to the overall sum (and since you didn't state any other
condition).

You'll have the same problem of occasionally (or more than occasionally,
perhaps) having to resample; whether that's acceptable or not on the
required population statistics or not is another question you'd have to
judge.

--

Subject: matrix generation

From: dpb

Date: 8 Nov, 2009 19:20:07

Message: 10 of 12

dpb wrote:
> jack j wrote:
> ...
>> But what if the condition is something like " (1st column element-2nd
>> column element)+(3rd column element-4th column element)"for all rows
>> should be equal to x???
>>
>> In this case will such a defn work out?
>
> Possibly depending on the size of the selection pool and value of x. The
> rudimentary case for the above would be generate three independently and
> solve for the fourth as the parentheses make no difference numerically
> to the overall sum (and since you didn't state any other condition).
>
> You'll have the same problem of occasionally (or more than occasionally,
> perhaps) having to resample; whether that's acceptable or not on the
> required population statistics or not is another question you'd have to
> judge.

NOTA BENE: In the above I assumed the "for all rows" means each row
independently satisfies the criterion.

--

Subject: matrix generation

From: jack j

Date: 9 Nov, 2009 03:55:18

Message: 11 of 12

dpb <none@non.net> wrote in message <hd75l9$alt$2@news.eternal-september.org>...
> dpb wrote:
> > jack j wrote:
> > ...
> >> But what if the condition is something like " (1st column element-2nd
> >> column element)+(3rd column element-4th column element)"for all rows
> >> should be equal to x???
> >>
> >> In this case will such a defn work out?
> >
> > Possibly depending on the size of the selection pool and value of x. The
> > rudimentary case for the above would be generate three independently and
> > solve for the fourth as the parentheses make no difference numerically
> > to the overall sum (and since you didn't state any other condition).
> >
> > You'll have the same problem of occasionally (or more than occasionally,
> > perhaps) having to resample; whether that's acceptable or not on the
> > required population statistics or not is another question you'd have to
> > judge.
>
> NOTA BENE: In the above I assumed the "for all rows" means each row
> independently satisfies the criterion.
>
> --

Yes, each row should independently satisfy the criterion.
What happens with the following condition?
(1st column element-2nd column element)^2+(3rd column element-4th column element)^2 should be greater than x.

Subject: matrix generation

From: dpb

Date: 9 Nov, 2009 05:52:15

Message: 12 of 12

jack j wrote:
...
> Yes, each row should independently satisfy the criterion.
> What happens with the following condition?
> (1st column element-2nd column element)^2+(3rd column element-4th
> column element)^2 should be greater than x.

What is this, 20 questions?

Work out the necessary algebra...

--

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com