Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Embedded For Loop?
Date: Wed, 11 Mar 2009 03:53:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 26
Message-ID: <gp7cit$10e$1@fred.mathworks.com>
References: <16409623.1236739893454.JavaMail.jakarta@nitrogen.mathforum.org>
Reply-To: <HIDDEN>
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 1236743581 1038 172.30.248.37 (11 Mar 2009 03:53:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 11 Mar 2009 03:53:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:523947

Carp Fisher <bmjim@gmail.com> wrote in message <16409623.1236739893454.JavaMail.jakarta@nitrogen.mathforum.org>...
> Lets say I have two arrays:
> 
> x = [1 2 3 4 5]
> y = [9 8 7 6 5]
> 
> How would I write a loop that would solve for 
> 
> z = x + y
> 
> for each different combination of x and y values, i.e 
> z(1,9) z(2,9) z(3,9)... etc?
> 
> Thanks,
> 
> Kim

  You could also do:

 z = round(log(exp(x.')*exp(y)));

assuming x and y contain only positive integers as in your example.  Otherwise remove the 'round' portion.

  To be candid with you, I don't actually recommend this method but only present it here as a curiosity.

Roger Stafford