View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

3.0 | 1 rating Rate this file 6 Downloads (last 30 days) File Size: 2.26 KB File ID: #36837 Version: 1.7
image thumbnail




23 May 2012 (Updated )

Fast approximation to the gradient for scattered data and for data defined by a triangulation.

| Watch this File

File Information

[ZX,ZY] = TRIGRADIENT(X,Y,Z,T) returns an approximation to the gradient of Z defined on the delaunay triangulation T. ZX corresponds to the gradient in the x direction, dZ/dX, and ZY corresponds to the gradient in the y direction dZ/dY.

If Z is a matrix of size MxN then ZX and ZY will be computed for each of the N columns of Z.

[ZX,ZY] = TRIGRADIENT(X,Y,Z) returns an approximation to the gradient of Z for the scattered data (X,Y).

[ZX,ZY] = TRIGRADIENT(X,Y,Z,'face') returns the value of the of the gradient for each triangular face assuming Z is a piece-wise planar function. ZX(1) is an approximation to the gradient in the x direction of the function Z for the triangle defined by the nodes [x(T(1,:)), y(T(1,:))].

Trigradient uses a first order approximation. Z is assumed to be a piece-wise planar function over the triangulated region. The partial derivative of each plane (ax + by + c = z) is a in the x direction and b in the y direction. A given node in the triangulation is associated with k triangles. The partial derivative at each node is the weighted sum of each of the partial derivatives of the triangles associated with that node. The weightings are the areas of each triangle divided by the total area of all triangles associated with that node.


Contours For Triangular Grids inspired this file.

This file inspired Mnuno/Trigradient2.

MATLAB release MATLAB 7.12 (R2011a)
Other requirements tricontour.m
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (1)
11 Oct 2016 SL

SL (view profile)

Something has changed in Matlab 2016a so I cannot run Duane's QuiverPlot, which uses your function `[U,V]=trigradient(tri,X,Y,Z);`. Error are `Error using horzcat
Dimensions of matrices being concatenated are not consistent. Error in trigradient (line 52) p = [x,y];`

24 May 2012 1.2

Fixed typos to handle z with multiple columns. Changed several typos in help documentation. Removed two ~ to prevent earlier versions from crashing.

24 May 2012 1.3

Corrected a typo in the error output.

29 May 2012 1.4

Found another typo in comments

08 Apr 2013 1.5

Code is now entirely vectorized. It no longer loops over each node.

Option to allow output of the gradient of individual triangular planes has been added.

08 Apr 2013 1.7

Fixed example code.
Fixed bug with number of inputs/options checks.

Contact us