我有一个包含各种值的数据表。它包括以下各列:
| Value 1 | Value 2 |
|---------|---------|
|0 |235 |
|1 |123 |
|1 |309 |
|1 |540 |
|2 |34 |
|3 |123 |
|3 |959 |
|3 |3939 |
我想要一个包含Value 2
的表,具体取决于Value 1
的每个值。它看起来是这样的:
| Value 1 | Value 2 |
| --------|----------------|
| 0 |[235] |
|1 |[123, 309, 540] |
|2 |[34] |
|3 |[123, 959, 3939]|
或者类似的东西。
我尝试了几种解决方案,例如:
t = table;
for i=1:length(existing_table)
t(existing_table, end+1) = existing_table.value2(i) % append to case i
end;
--> returns Error using ()
Right hand side of an assignment into a table must be another table or a cell array.
--------------
t = table;
for i=1:length(existing_table)
switch existing_table.value2(i)
case 0
t(0, end+1) = existing_table.value2(i) % append to case
0
% etc...
end;
end;
--> returns Error using ()
Right hand side of an assignment into a table must be another table or a cell array.
--------------
t = table;
t.v1 = value1;
t.v2 = unique(value2) % Does not return the kind of table that I would like
1条答案
按热度按时间snz8szmq1#
这听起来像是
accumarray
的工作: