trying to calculate the central diff approximation

1 回表示 (過去 30 日間)
isamh
isamh 2020 年 2 月 10 日
コメント済み: Jim Riggs 2020 年 2 月 10 日
i tried multiple ways but none of them worked. kind of stuck and not sure what to do. what i'm trying to do is find current value that is equal to one ahead minus one below all divided by .2
code is:
Phase_1 = DATA(DATA(:,4)==1,:);
Vroll_avg1_1 = movsum((1/5).*Phase_1(:,3),[2 2]);
Vdi_1 = movsum(1/5.*Vroll_avg1_1,[2 2]);
---> first try: Adi_1 = [Vdi_1(2:Vdi_1+1,:)-Vdi_1(1:Vdi_1-1,:)/(2*T)];
---> second try: Adi_1 = ((Vdi_1(2:end+1) - Vdi_1(1:end-1))/(2*T)); % error says index exceeds array bounds. i understand why but how((2:end+1)) would i get it to work?
---> third try: %K = length(Vdi_1);
%Q = length(Vti_1);
%for M = 2:(length(Vdi_1)-1)
% Adi_1 = ((Vdi_1 - Vdi_1)./(2.*T));
%end
%Adi_1 = (Vdi_1(2) - Vdi_1(1))./(2.*T);
%Adi_1(length(Vdi_1)) = (Vdi_1(K) - Vdi_1(K))./(2.*T);
really need help, please try to help me figure this out.

採用された回答

Jim Riggs
Jim Riggs 2020 年 2 月 10 日
編集済み: Jim Riggs 2020 年 2 月 10 日
There is a Matlab function "diff" which will do this.
Otherwise, your subscripts must all match (2:end-1)
Adi_1 = diff(Vdi_1);
or
for i=2:numel(Vdi_1)-1
Adi_1(i) = (Vdi_1(i+1) - Vdi_1(i-1))/2/T;
end
  11 件のコメント
isamh
isamh 2020 年 2 月 10 日
編集済み: isamh 2020 年 2 月 10 日
im so sorry jim, just got it to work. forsome reason i had one of the numel as nume1 with the #1. got it to work, thanks!
Jim Riggs
Jim Riggs 2020 年 2 月 10 日
Very good.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by