How to differentiate elements in a matrix by each other

12 ビュー (過去 30 日間)
Darren Nutting
Darren Nutting 2019 年 8 月 19 日
コメント済み: Darren Nutting 2019 年 8 月 20 日
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

採用された回答

Jon
Jon 2019 年 8 月 19 日
編集済み: Jon 2019 年 8 月 19 日
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
  3 件のコメント
Jon
Jon 2019 年 8 月 19 日
Glad to hear that helped. To obtain, perhaps better accuracy, you might want to estimate the derivatives using central difference approximations for the interior (ones other than the first and last) points. You could then use forward differences and backward differences for the endpoints. If your magnetic field strength (first column in your matrix) values are equally spaced, you can do this using the gradient function. Enter the following on the command line and you will get the documentation for that.
doc gradient
One nice thing about the gradient function is that it returns a derivative for every point, rather than just for 2:end
Darren Nutting
Darren Nutting 2019 年 8 月 20 日
Okay I will give it a go. Thanks again :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by