Path: news.mathworks.com!newsfeed-00.mathworks.com!newscon02.news.prodigy.net!prodigy.net!news.glorb.com!news.aset.psu.edu!not-for-mail
From: dvt <dvt+usenet@psu.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How to find Horizontal & Vertical Gradients?
Date: Sat, 05 Jan 2008 17:18:12 -0500
Organization: Penn State University, Center for Academic Computing
Lines: 39
Message-ID: <flovn7$102o$1@f04n12.cac.psu.edu>
References: <fd664390-3ad5-4a89-9f65-a824f963677c@q39g2000hsf.googlegroups.com>
NNTP-Posting-Host: vpn2-1-34.cac.psu.edu
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: f04n12.cac.psu.edu 1199571495 32856 172.25.1.34 (5 Jan 2008 22:18:15 GMT)
X-Complaints-To: usenet@f04n12.cac.psu.edu
NNTP-Posting-Date: Sat, 5 Jan 2008 22:18:15 +0000 (UTC)
User-Agent: Thunderbird 2.0.0.9 (Windows/20071031)
In-Reply-To: <fd664390-3ad5-4a89-9f65-a824f963677c@q39g2000hsf.googlegroups.com>
Xref: news.mathworks.com comp.soft-sys.matlab:444501


selvi wrote:
> Hi,
>    I want to implement the following Equations in MATLAB to find hori
> & Vert Gradient.
> 
> DH = | x(i , j-2) + x(i ,,j+2) - 2x(i, j) |  +  | x(i,,j-1) - x(i,,j
> +1) |
> 
> DV = | x(i-2, j) + x(i+2,,j) - 2x(i, j) |  +  | x(i-1, j) - x(i+1,,j)
> |
> 
> If(DH+35< DV)
> 
>    G={ [ x(i,,j-1) + x(i,,j+1) ] /2 }    +   { [ 2x(i, j) - x(i , j-2)
> - x(i ,,j+2) ]/4}

If I understand your question, try something like the following:

x = rand(10);
Ga = zeros(10); %preallocate
DHa = Ga;
DVa = Ga;

i = 3:8;
j = 3:8;
DH(i,j) = abs( x(i,j-2) + x(i,j+2) - 2*x(i,j) )  +...
     abs( x(i,j-1) - x(i,j+1) );
DV(i,j) =abs( x(i-2,j) + x(i+2,j) - 2*x(i,j) )  +...
     abs( x(i-1,j) - x(i+1,j) );
mask = ((DH+35)< DV);
G(i,j) = ( x(i,j-1) + x(i,j+1) ) /2 +...
     ( 2*x(i,j) - x(i,j-2) - x(i,j+2) )/4;
G = mask .* G;

As Roger pointed out, you should look into the meanings of {}, [], and 
() in Matlab.
-- 
Dave
dvt at psu dot edu