Finding difference between two rows

7 ビュー (過去 30 日間)
Karina
Karina 2018 年 4 月 25 日
コメント済み: Dooyoung Kim 2018 年 6 月 28 日
I have a 6696502 x 2 table which shows energy in MW for a period of time. I want to add a column which is the difference in energy for each time period so column 3 row 2 shows the difference in values for row 2 and 1 in column 2.
I have the following code, however it is very slow to compute given my table is so large. if true
if true
% code
for n = 1:countReg
if n == 1
diffReg = 0;
else
diffReg = RegCol(n) - RegCol(n-1);
end
newRegTable.ChangeReg(n) = diffReg;
end
end
Is there any way to do this so it does not take so much time?

回答 (1 件)

Guillaume
Guillaume 2018 年 4 月 25 日
yourtable.ChangeReg = [0; diff(yourtable.NameOfFirstColumn)]
  1 件のコメント
Dooyoung Kim
Dooyoung Kim 2018 年 6 月 28 日
Works well! Thank you :)

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by