필터 지우기
필터 지우기

How to divide data into different cells?

조회 수: 3 (최근 30일)
Ahmad Kamal Bin Mohd Nor
Ahmad Kamal Bin Mohd Nor 2019년 8월 28일
댓글: Jon 2019년 8월 28일
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
Ahmad Kamal Bin Mohd Nor
Ahmad Kamal Bin Mohd Nor 2019년 8월 28일
here is the MAT file with the dataTrain table
you can use the code I had given to test
Ahmad Kamal Bin Mohd Nor
Ahmad Kamal Bin Mohd Nor 2019년 8월 28일
if you run the code, it will take some time.

댓글을 달려면 로그인하십시오.

채택된 답변

Jon
Jon 2019년 8월 28일
편집: Jon 2019년 8월 28일
Your looping logic looks quite complicated, and it is difficult to follow exactly what your intent is here. From your verbal description it sounded like you just want to make two cell arrays one with the input data and the other with the output data.
So is what you are trying to do just as simple as the following or am I not understanding what you are trying to accomplish (I'm assuming you want the individual number and time in both arrays)
Xtrain = horzcat(dataTrain(:,1:2),dataTrain(:,4:end))
Ytrain = dataTrain(:,1:3)
I would also recommend that for this type of data you are much better of either using MATLAB tables or if infact this is actually time series data use a timetable
For more info, on the command line enter
doc timetable
or enter
doc table
  댓글 수: 5
Ahmad Kamal Bin Mohd Nor
Ahmad Kamal Bin Mohd Nor 2019년 8월 28일
wow... this works
thanks!!!!
Jon
Jon 2019년 8월 28일
Excellent! I've found that working with MATLAB tables has hugely simplified a lot of data analysis that I do.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by