Path: news.mathworks.com!not-for-mail
From: "Sadik " <sadik.hava@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Random for basic artihmetic operations
Date: Mon, 25 May 2009 22:07:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 38
Message-ID: <gvf4q5$o56$1@fred.mathworks.com>
References: <4a15cb07$0$31332$9b4e6d93@newsspool4.arcor-online.net> <gv50pd$ib3$1@fred.mathworks.com> <4a1b0740$0$30229$9b4e6d93@newsspool1.arcor-online.net>
Reply-To: "Sadik " <sadik.hava@gmail.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1243289221 24742 172.30.248.37 (25 May 2009 22:07:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 25 May 2009 22:07:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1666517
Xref: news.mathworks.com comp.soft-sys.matlab:542458


How about this one?

A = 1;
B = 2;
C = 3;

arth_operations = ['+','-','*','/'];

opDraw = ceil(4*rand(2,1));
opDraw(opDraw==0)=1; %If there are any zeroes, they should be 1.

eval(['Result = A' arth_operations(opDraw(1)) 'B' arth_operations(opDraw(2)) 'C;'])


"Sven Schulz" <sven-schu@arcor.de> wrote in message <4a1b0740$0$30229$9b4e6d93@newsspool1.arcor-online.net>...
> Justin Abbott wrote:
> > % Cell array of function handles to the desired operations
> > op = {@plus @times @minus @rdivide};
> > % Pick 3 operations with replacement
> > opDraw = ceil(4*rand(3,1));
> > val = op{opDraw(1)}(A,op{opDraw(2)}(op{B,opDraw(3)}(C,D)));
>  
>  Hi Justin,
> thank you for your inspiration.
> 
> My favorite code could luck like this
> 
> A=1;
> B=2;
> C=3;
> 
> arth_operations = [+ - * /];
> 
> Result = Arandom(arth_operations)Brandom(arth_operations)C
> 
> But, no idea to create code like this.
> 
> Sven