필터 지우기
필터 지우기

Merge multi-row values to single row in table for classification training

조회 수: 3 (최근 30일)
Omega Wea
Omega Wea 2018년 1월 15일
답변: Eric Tao 2018년 2월 9일
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.

답변 (1개)

Eric Tao
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;

카테고리

Help CenterFile Exchange에서 Sequence and Numeric Feature Data Workflows에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by