How to number rows of a table by group

4 次查看(过去 30 天)
I have a table with 2-3 rows per subject(PATID). Now, I would like to add a column which indicate if it is the first, second or third training of a patient (as shown in the figure). There must be a simple way, but I cant figure it out.
Thanks for your help

采纳的回答

jonas
jonas 2018-10-17
编辑:jonas 2018-10-17
Can try something like this:
PATID = [1 1 3 3 3 5 9 9 12]'
T = table(PATID)
out = varfun(@(x)1:length(x),T,'InputVariables','PATID','GroupingVariables','PATID','OutputFormat','cell')
out = [out{:}]'
Just put out in a new column.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by