Path: news.mathworks.com!newsfeed-00.mathworks.com!kanaga.switch.ch!switch.ch!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsfeed.straub-nv.de!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Basic Matlab help
Date: Wed, 21 Apr 2010 19:23:06 -0500
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <hqo50f$7vi$1@news.eternal-september.org>
References: <hqo2po$h11$1@fred.mathworks.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 22 Apr 2010 00:24:48 +0000 (UTC)
Injection-Info: news.eternal-september.org; posting-host="+vXiRB9knG1OYC0iOMVdug";
	logging-data="8178"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/o0uYhcUxKUfL6Z1mwSFNO"
User-Agent: Thunderbird 2.0.0.24 (Windows/20100228)
In-Reply-To: <HIDDEN>
Cancel-Lock: sha1:qZHVl1nFHnjPRM5sgg7dHs6jtsc=
Xref: news.mathworks.com comp.soft-sys.matlab:628712

Ashley Wright wrote:
> I'm really rusty with MATLAB and need some assistance.  I'm trying to 
> write a code to take r = sqrt((D-y)^2+x^2) and its not working out the 
> way I would like.  x and y are values from 1 to 1000. I'd like MATLAB to 
> calculate r1 using the equation above for each combination of values in 
> the matrix.  For example:
> 
> r(1,1) would be sqrt((D-1)^2+1^2), r(1,2) would be sqrt((D-1)^2+2^2), 
> ..., r(x,y) = sqrt((D-y)^2+x^2), etc.  How do I go about doing that?  I 
> can do it with loops, but that is very inefficient.  Thanks for the help.

Or, just for grins compared to others...

R=abs(complex(D-Y,X));

:)

--