Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: function gradient.
Date: Mon, 17 May 2010 18:20:22 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 37
Message-ID: <hss1d5$dc1$1@fred.mathworks.com>
References: <hsrn4j$o85$1@fred.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1274120422 13697 172.30.248.35 (17 May 2010 18:20:22 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 17 May 2010 18:20:22 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:636569

"zhang " <xiaoc10@gmail.com> wrote in message <hsrn4j$o85$1@fred.mathworks.com>...
> I want to use function gradient to compute a matrix.
> For example:
> x = [2 4 5; 5 6 9; 0 1 3];
> [fx, fy] = gradient(x);
> 
> fx and fy are both 3*3 matix.
> 
> My question is how to get a 3*3 result? It seems that we can only
> get a 2*2 result?

Odd,  I *do* get (3 x 3) matrix

>> x = [2 4 5; 5 6 9; 0 1 3]

x =

     2     4     5
     5     6     9
     0     1     3

>> [fx, fy] = gradient(x)

fx =

    2.0000    1.5000    1.0000
    1.0000    2.0000    3.0000
    1.0000    1.5000    2.0000


fy =

    3.0000    2.0000    4.0000
   -1.0000   -1.5000   -1.0000
   -5.0000   -5.0000   -6.0000

Bruno