How to differentiate the data in excel using a variable?

7 ビュー (過去 30 日間)
Vishnuvardhan Naidu Tanga
Vishnuvardhan Naidu Tanga 2022 年 11 月 18 日
コメント済み: Star Strider 2022 年 11 月 21 日
Hello all,
I am trying to do a differentiation of a variable in excel data with respect to an other variable. For example in my case, the data which has a name in Y in excel has to be differentiated with respect to X. and I need each value after differentiation. Can someone please tell me how can i do it. I am attaching the excel data.
  5 件のコメント
Vishnuvardhan Naidu Tanga
Vishnuvardhan Naidu Tanga 2022 年 11 月 19 日
hello @Jan
Thanks for your reply. I can import the data into matlab its not the issue. The issue is how can i integrate one coloum with respect to other?
Jan
Jan 2022 年 11 月 20 日
If you have imported the data already, it is useful to post a small example, how they are represented in Matlab.
You asked for a differentiation at first, but now for an integration. While gradient(x,t) does the first, trapz(x,t) does the second.

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

採用された回答

Star Strider
Star Strider 2022 年 11 月 20 日
You can use the gradient function to calculate the numerical derivative —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1198533/matlab.xlsx')
T1 = 83×14 table
X1 Y1 X2 Y2 X3 Y3 X4 Y4 X5 Y5 X6 Y6 X7 Y7 _____ ______ _____ ______ _____ ______ _____ ______ _____ ______ _____ ______ _____ ______ 0 2.3438 0 1.9952 0 1.7367 0 1.5374 0 1.3791 0 1.2502 0 1.1433 0.002 2.3397 0.002 1.9926 0.002 1.735 0.002 1.5363 0.002 1.3782 0.002 1.2496 0.002 1.1428 0.004 2.328 0.004 1.9854 0.004 1.7303 0.004 1.533 0.004 1.3759 0.004 1.2478 0.004 1.1415 0.006 2.3081 0.006 1.9731 0.006 1.7221 0.006 1.5273 0.006 1.3717 0.006 1.2448 0.006 1.1391 0.008 2.2805 0.008 1.9559 0.008 1.7107 0.008 1.5194 0.008 1.366 0.008 1.2405 0.008 1.1359 0.01 2.2459 0.01 1.9342 0.01 1.6963 0.01 1.5093 0.01 1.3587 0.01 1.235 0.01 1.1317 0.012 2.2047 0.012 1.9083 0.012 1.6789 0.012 1.4971 0.012 1.3498 0.012 1.2284 0.012 1.1266 0.014 2.1574 0.014 1.8783 0.014 1.6587 0.014 1.4829 0.014 1.3395 0.014 1.2206 0.014 1.1206 0.016 2.1048 0.016 1.8445 0.016 1.6359 0.016 1.4668 0.016 1.3277 0.016 1.2117 0.016 1.1138 0.018 2.0475 0.018 1.8074 0.018 1.6106 0.018 1.4489 0.018 1.3146 0.018 1.2018 0.018 1.1061 0.02 1.986 0.02 1.7672 0.02 1.5831 0.02 1.4292 0.02 1.3001 0.02 1.1909 0.02 1.0976 0.022 1.921 0.022 1.7243 0.022 1.5535 0.022 1.408 0.022 1.2844 0.022 1.179 0.022 1.0884 0.024 1.8531 0.024 1.679 0.024 1.5219 0.024 1.3853 0.024 1.2676 0.024 1.1662 0.024 1.0784 0.026 1.7826 0.026 1.6316 0.026 1.4887 0.026 1.3612 0.026 1.2496 0.026 1.1524 0.026 1.0677 0.028 1.71 0.028 1.5825 0.028 1.4539 0.028 1.3358 0.028 1.2306 0.028 1.1379 0.028 1.0564 0.03 1.6376 0.03 1.5319 0.03 1.4178 0.03 1.3094 0.03 1.2107 0.03 1.1226 0.03 1.0444
[~,dx] = gradient(T1{:,1:2:end});
[~,dy] = gradient(T1{:,2:2:end});
dydx = dy ./ dx
dydx = 83×7
-2.0334 -1.2536 -0.8270 -0.5738 -0.4141 -0.3086 -0.2363 -3.9356 -2.4292 -1.6035 -1.1132 -0.8039 -0.5994 -0.4588 -7.9144 -4.8967 -3.2368 -2.2494 -1.6258 -1.2128 -0.9284 -11.8807 -7.3784 -4.8889 -3.4029 -2.4622 -1.8383 -1.4082 -15.5456 -9.7043 -6.4515 -4.5009 -3.2621 -2.4383 -1.8696 -18.9659 -11.9156 -7.9548 -5.5657 -4.0421 -3.0260 -2.3229 -22.1116 -13.9961 -9.3901 -6.5923 -4.7995 -3.5995 -2.7670 -24.9582 -15.9306 -10.7479 -7.5752 -5.5307 -4.1567 -3.2005 -27.4927 -17.7088 -12.0214 -8.5097 -6.2326 -4.6954 -3.6220 -29.7107 -19.3243 -13.2052 -9.3919 -6.9027 -5.2140 -4.0301
figure
for k = 1:size(dydx,2)
subplot(4,2,k)
yyaxis left
plot(T1{:,(2*k-1)}, T1{:,(2*k-1)+1})
ylim([0 4])
yyaxis right
plot(T1{:,(2*k-1)}, dydx(:,k))
xlim([0 0.2])
ylim([-40 0])
grid
title(sprintf('X%d,Y%d',[1 1]*k))
end
hl = legend('Data','Derivative');
hs42 = subplot(4,2,8);
hs42.Visible = 'off';
hl.Position = hs42.Position;
% figure % Check First & Last Assignments
% yyaxis left
% plot(T1.X1, T1.Y1, T1.X7, T1.Y7)
% yyaxis right
% plot(T1.X1,dydx(:,1), T1.X7,dydx(:,7))
% grid
This appears to me to be correct. Check it to be certain it produces the desired result.
.
  2 件のコメント
Vishnuvardhan Naidu Tanga
Vishnuvardhan Naidu Tanga 2022 年 11 月 21 日
Thank you @Star Strider. I am getting the desired results.
Star Strider
Star Strider 2022 年 11 月 21 日
As always, my pleasure!
This was an interesting problem!
.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by