Continuous Loop operation with conditional statements in table and then calculation

4 ビュー (過去 30 日間)
I have a table that I brought into Matlab (165185x13 table), and it contains position function and time fucntion which is discontinuous and I'm trying to run a function in which it will take values when time difference is 1 and will calculate difference between last and first postion value with respect to time function. Again loop should be restarted when after discontinuous time difference will again one and respective position difference should be added to previous value.
for eg. position value calculation = (481-464)+(2272-2244)+......
I couldn't get the logic how can I do it.
Thanks in advance

採用された回答

Stephen23
Stephen23 2020 年 12 月 28 日
編集済み: Stephen23 2020 年 12 月 28 日
No need to use a loop:
T = [1317;1327;1342;1390;1391;1392;1393;1446;1453;1464;1491;1607;1608;1609];
D = diff([false;diff(T)==1;false]);
B = find(D>0);
E = find(D<0);
P = [41.84;64.97;129.8;464.6;470.6;476.4;481.8;539.0;555.9;604.3;801.2;2245;2259;2273];
N = sum(P(E)-P(B))
N = 45.2000
For comparison:
(481.8-464.6)+(2273-2245)
ans = 45.2000
  2 件のコメント
Ashwini  More
Ashwini More 2020 年 12 月 28 日
Thank you Stephen for your answer!
but I want to add that attached picture is just for example, I want to do this process for entire table (165185x13 table). again I tried your code in my existing code but there is error as undefined variable for 'diff' command.
Stephen23
Stephen23 2020 年 12 月 29 日
Because you did not upload any data I used simple numeric vectors P and T. Of course you will need to replace them with the appropriate variables of your table.

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

その他の回答 (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