How to divide data into different cells?
古いコメントを表示
Ok stuck here. Pls gives some help.
dataTrain is a table of all my data. This is a time series dataset. It has more than 20 variables. Variable 1 is the individual no. There are 'n' = 260 individuals. Variable 2 is time. Variable No. 3 is the 'Output' while No. 4 to end are the 'Inputs'
I want to divide all of this data into cells of Xtrain(Inputs) and Ytrain(Output) according to individual no.
This is my code
Xtrain = cell(n,1);
Ytrain = cell(n,1);
i = 1;
j = 1;
k = 1;
for j = 1:n;
while dataTrain{i,1} == j;
L(:,i)= dataTrain{i,4:end};
M(:,i)= dataTrain{i,3};
i = i + 1;
end
Xtrain{j,:} = L(:,k:i-1);
Ytrain{j,:} = M(:,k:i-1);
k = i;
j = j + 1;
end
However when I do this, Xtrain and Ytrain stopped at 259, Matlab gives 'Row index exceeds table dimensions.'
6 件のコメント
Walter Roberson
2019 年 8 月 28 日
What happens if you get to i == 260 and dataTrain{260,1) == j ?
Ahmad Kamal Bin Mohd Nor
2019 年 8 月 28 日
編集済み: Ahmad Kamal Bin Mohd Nor
2019 年 8 月 28 日
the cyclist
2019 年 8 月 28 日
Can you upload your data in a MAT file, so that we can actually run your code?
the cyclist
2019 年 8 月 28 日
編集済み: the cyclist
2019 年 8 月 28 日
Could it be that the following condition
while dataTrain{i,1} == j
is not met because the value in dataTrain is a floating-point number that is very close to, but not exactly, equal to j, so the while loop exits before you expect?
Ahmad Kamal Bin Mohd Nor
2019 年 8 月 28 日
Ahmad Kamal Bin Mohd Nor
2019 年 8 月 28 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!