how to calculate partial derivative

RGB =imread('image.jpg');
hsv= rgb2hsv(RGB);
imshow(hsv);
r1=0.1;
r2=0.85;
i= 0:20:240;
s= 0.0:0.2:1.0;
wgray = 1 - bsxfun(@power, s(:), (r1*(255./(i(:).')).^r2) );
P=diff(wgray,s);
i want to calculate partial derivative of wgray w.r.t s and i have applied but getting error in line 9

 Accepted Answer

Star Strider
Star Strider on 4 Feb 2016
I would use the gradient function. It returns two matrices, the partial derivatives in each direction of the input matrix, both the same size as the input matrix. You can use one or both of the returned derivative matrices.

6 Comments

Ok sir...as Wgray is a matrix they are again giving error and i have applied gradient(wgray,s) i want to calculate partial derivative of wgray w.r.t s. Actually m new to matlab so getting some difficulty
Thanks..
The gradient function wants a single non-zero scalar value for the second argument that represents the (assumed) constant spacing in a particular direction.
Since the step in your ‘s’ vector is 0.2, you would call the gradient function as:
[FX,FY] = gradient(wgray, 0.2);
That should work.
Thank u so much sir.. As value of s varies from 0.2 to 1.0 i need to use gradient function 6 times gradient(wgray,0.2); gradient(wgray,0.4); gradient(wgray,0.6); gradient (wgray,0.8); gradient(wgray,1.0);
thanks once again.
If your constant step size varies, you would either need to re-calculate the numerical gradient, or interpolate a gradient calculated from a lower (finer) step size to a different step size.
If it is a vector of step sizes varying over the dimensions of the vector or matrix you are calculating the gradient of, if I remember correctly, there are File Exchange contributions that will allow you to use a varying grid width to calculate the gradient. Search the File Exchange to see which of those works best for you.
As always, my pleasure.

Sign in to comment.

More Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Products

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!