How would I calculate the change in columns of one table and display it in another?

조회 수: 1 (최근 30일)
For example, I have a table:
User Date1 Date2 Date3 ....(I have 500+ dates)
{'A'} 1 6 10 ...
{'B'} 2 8 11 ...
{'C'} 3 9 14 ...
{'D'} 4 11 11 ...
I would like to create this table, showing the changes as each date progresses
User Date2 Date3 ....(I have 500+ dates)
{'A'} 5 4 ...
{'B'} 6 3 ...
{'C'} 6 5 ...
{'D'} 7 0 ...

채택된 답변

Cris LaPierre
Cris LaPierre 2020년 11월 12일
You won't be able to do this with tables. Using Accessing Data in Tables, extract the data, take the diff along dimension 2, then build a new table from the results.
Date1 = [1:4]';
Date2 = [6 8 9 11]';
Date3 = [10 11 14 11]';
User = ["A" "B" "C" "D"]';
T = table(User,Date1,Date2,Date3)
T = 4x4 table
User Date1 Date2 Date3 ____ _____ _____ _____ "A" 1 6 10 "B" 2 8 11 "C" 3 9 14 "D" 4 11 11
T2 = diff(T{:,2:end},[],2)
T2 = 4×2
5 4 6 3 6 5 7 0
T2 = table(T.User,T2);
T2=splitvars(T2);
T2.Properties.VariableNames = T.Properties.VariableNames([1,3:end])
T2 = 4x3 table
User Date2 Date3 ____ _____ _____ "A" 5 4 "B" 6 3 "C" 6 5 "D" 7 0

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by