MATLAB: How to differentiate elements in a matrix by each other

matrix manipulation

Hi,
Suppose I have a matrix with 2 columns and an abritrary number of rows, and that the columns represent two variables (magnetic field strength B and magnetoresistance M_r, respectively). How do I go about differentiating this matrix so that I can plot d(M_r)/dB against B?
I am pretty new to MATLAB so I have no idea how to approach this myself.
Thanks

Best Answer

Say your matrix is called M, you could do something like
% find incremental change from one row to the next
delta = diff(M);
% compute approximate derivatives
dM_rdB = delta(:,2)./delta(:,1) % note ./ does division element by element
% plot results
plot(M(2:end),dM_rdB) % M has one less row than the derivative, start at second element