Path: news.mathworks.com!not-for-mail
From: "Shawn Bonneau" <sbonneau@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How to random a matrix B to add to Matrix A with same order
Date: Tue, 14 Jun 2011 10:10:05 -0400
Organization: MathWorks
Lines: 49
Message-ID: <it7q3t$o4a$1@newscl01ah.mathworks.com>
References: <it79nd$9i6$1@newscl01ah.mathworks.com> <it7amp$bms$1@newscl01ah.mathworks.com> <5c260e58-4349-4989-8e00-c7ef4059795d@v31g2000vbs.googlegroups.com> <it7poo$mvk$1@newscl01ah.mathworks.com>
Reply-To: "Shawn Bonneau" <sbonneau@mathworks.com>
NNTP-Posting-Host: ah-sbonneau.dhcp.mathworks.com
Mime-Version: 1.0
Content-Type: text/plain;
	format=flowed;
	charset="UTF-8";
	reply-type=response
Content-Transfer-Encoding: 7bit
X-Trace: newscl01ah.mathworks.com 1308060605 24714 172.31.91.211 (14 Jun 2011 14:10:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 14 Jun 2011 14:10:05 +0000 (UTC)
In-Reply-To: <it7poo$mvk$1@newscl01ah.mathworks.com>
X-Priority: 3
X-MSMail-Priority: Normal
Importance: Normal
X-Newsreader: Microsoft Windows Live Mail 14.0.8089.726
X-MimeOLE: Produced By Microsoft MimeOLE V14.0.8089.726
Xref: news.mathworks.com comp.soft-sys.matlab:731859

Use the sort command on C, after you have already added the B matrix.

"Kittikorn Tongnimitsawat" <kittikornt@hotmail.com> wrote in message 
news:it7poo$mvk$1@newscl01ah.mathworks.com...
> Torsten <Torsten.Hennig@umsicht.fraunhofer.de> wrote in message 
> <5c260e58-4349-4989-8e00-c7ef4059795d@v31g2000vbs.googlegroups.com>...
>> On 14 Jun., 11:47, "Kittikorn Tongnimitsawat" <kittiko...@hotmail.com>
>> wrote:
>> > "Kittikorn Tongnimitsawat" wrote in message 
>> > <it79nd$9i...@newscl01ah.mathworks.com>...
>> > > I have a vector A with descending order like this
>> >
>> > > A =
>> >
>> > > 0.958
>> > > 0.6843
>> > > 0.4391
>> > > 0.329
>> > > 0.012
>> >
>> > > I would like to create matrix B with random number between -0.05 and 
>> > > 0.05 to add to matrix A, let say C = A + B. There is a constraint is 
>> > > that C has to have the descending order like A.
>> >
>> > > Can anyone please advise? Thanks in advance.
>> >
>> > Actually I have tried to use a loop to random matrix B until it fits 
>> > the constraint. However, if matrix A has many rows, like 50 - 100 rows, 
>> > it takes more than 1-2 hours to find the solution. and I have to do 
>> > like this for 50000 times for my montecarlo simulation. Is there any 
>> > better solution?
>>
>> First create a random matrix B of the same size as A with random
>> numbers between 0 and 1.
>> Then transform them according to B=-0.05+0.1*B to get random numbers
>> between -0.05 and 0.05.
>> Then use the sort-command to sort them in descending order.
>>
>> Best wishes
>> Torsten.
>
> Thanks Torsten. Unfortunately by doing this, the random will be bias. 
> Meaning to say that the first item of matrix A will be likely increasing 
> and the last item of matrix A will be decreasing. This is from positive 
> value in first item in Matrix B and negative value in last item.
>
> :( Hope there is a solution in the space..........
> Cheers!