Path: news.mathworks.com!newsfeed-00.mathworks.com!news.tele.dk!feed118.news.tele.dk!feed116.news.tele.dk!bofh.vszbr.cz!news.radio.cz!newsreader4.netcologne.de!news.netcologne.de!newsfeed.straub-nv.de!news.mixmin.net!aioe.org!.POSTED!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Generate random points on a circular sector
Date: Sun, 06 May 2012 12:05:23 -0500
Organization: Aioe.org NNTP Server
Lines: 48
Message-ID: <jo6b0h$h18$1@speranza.aioe.org>
References: <jo6784$eqn$1@newscl01ah.mathworks.com> <jo68g9$aj5$1@speranza.aioe.org>
Reply-To: <HIDDEN>
NNTP-Posting-Host: JFgm6aMVwmC/YQNQyUTYRQ.user.speranza.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Complaints-To: abuse@aioe.org
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20120428 Thunderbird/12.0.1
X-Notice: Filtered by postfilter v. 0.8.2
Xref: news.mathworks.com comp.soft-sys.matlab:767006

On 5/6/2012 11:22 AM, Nasser M. Abbasi wrote:
> On 5/6/2012 11:01 AM, Valentina wrote:
>> Hi.
>>
>> I am trying to generate random points in cartesian coordinates inside a
>> circular sector defined by the radius R and the angle w (I suppose the
>> center in (0,0) and that the angle is in [-w,w]).
>>
>> If anyone has a sample code or can help me with this, thanks for the help.
>
> may be
>
> ------------------------
> clear all; close all;
>
> angle = @(w)  -w+2*w*rand();
> rad   = @(r)  r*rand();
>
> N = 30;     %how many points
> w = pi/4;   %range of anlge [-w,w]
> r = 1;      %radius
>
> points = arrayfun(@(i) [angle(w) rad(r) ],1:N, 'UniformOutput',false);
> points = cell2mat(points(:));
> polar(points(:,1),points(:,2),'or')
>
> -----------------------------------------
>
> --Nasser

Ok, here is a version without arrayfun (I know some here do not
like arrayfun :)

-------------------------------
N = 30;     %how many points
w = pi/4;   %range of anlge [-w,w]
r = 1;      %radius

angle = -w+2*w*rand(N,1);
rad   = r*rand(N,1);
polar(angle,rad,'or')
----------------------------

--Nasser