Merge multi-row values to single row in table for classification training
1 次查看(过去 30 天)
显示 更早的评论
Hi, i am stuck in preparing data for training. i have a table like
P Q
5 4
3 3
2 3
1 4
1 5
...
i wish to create another table from it like:
P(t-5) Q(t-5) P(t-5) Q(t-5) P(t-5) Q(t-5) P(t-5) Q(t-5) P(t) Q(t)
0 0 0 0 0 0 0 0 5 4
0 0 0 0 0 0 5 4 3 3
0 0 0 0 5 4 3 3 2 3
0 0 5 4 3 3 2 3 1 4
5 4 3 3 2 3 1 4 1 5
...
For a big dataset, i wonder except for for-loop, if there is any other ways to compute it? i actually want to feed this small section(curve) data to train my classification. i wonder if this is a good idea.
0 个评论
回答(1 个)
Eric Tao
2018-2-9
Assume your original table is called 'data', and results will be stored in a new table called 'new', then run:
new = table();
new.P_minus4 = [zeros(4,1);data.P(1:end-4)];
new.Q_minus4 = [zeros(4,1);data.Q(1:end-4)];
new.P_minus3 = [zeros(3,1);data.P(1:end-3)];
new.Q_minus3 = [zeros(3,1);data.Q(1:end-3)];
new.P_minus2 = [zeros(2,1);data.P(1:end-2)];
new.Q_minus2 = [zeros(2,1);data.Q(1:end-2)];
new.P_minus1 = [zeros(1,1);data.P(1:end-1)];
new.Q_minus1 = [zeros(1,1);data.Q(1:end-1)];
new.P = data.P;
new.Q = data.Q;
And you will get what you want. If you want the code to be more concise, run this lines:
new = table();
for i = 4:-1:1
m = num2str(i);
eval(['new.P_minus',m,' = [zeros(',m,',1);data.P(1:end-',m,')];']);
eval(['new.Q_minus',m,' = [zeros(',m,',1);data.Q(1:end-',m,')];']);
end
new.P = data.P;
new.Q = data.Q;
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!