Effacer les filtres
Effacer les filtres

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

3 vues (au cours des 30 derniers jours)
Omega Wea
Omega Wea le 15 Jan 2018
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.

Réponses (1)

Eric Tao
Eric Tao le 9 Fév 2018
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;

Catégories

En savoir plus sur Sequence and Numeric Feature Data Workflows dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by