finding sub sequences of a data set

clc
clear
ts = xlsread('SwedishLeaf_TRAIN.xlsx');
l=length(ts);
for i = 1:500
p=ts(i,:)
for ii = 1:129
subSequence(ii,:) = p((ii-1)*30+ 1:ii*30);
end
I used the above code for finding the subsequences,but it not working.How can I find the subsequence of this.

댓글 수: 4

Star Strider
Star Strider 2019년 11월 8일
How do you define ‘subsequence’?
Silpa K
Silpa K 2019년 11월 8일
Iam trying to divide the sequence into subsequence,for that Iam trying to split 30 points each.
Star Strider
Star Strider 2019년 11월 8일
You need to describe in detail what your data are, and what you want to do.
Silpa K
Silpa K 2019년 11월 8일
I attached data set.I need to split each row.Each 30 points I need to separate from each row.

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

답변 (1개)

Ajay Pattassery
Ajay Pattassery 2019년 11월 11일

0 개 추천

I assume you want to extract a sub-vector of length 30 from each row. But the total length of the column is 129 which is not divisible by 30. Hence the 5th sub-vector will take 21 elements from the second row and it goes on.
subsequence = (reshape(ts',30,[]))'
If you have a constraint to keep the column length 129 and wish to have sub-parts elements from the same row together, you could split the matrix into two parts. One exactly divisible by 30.
ts1 = ts(:,1:120);
Subsequence1 = (reshape(ts1',30,[]))';
Subsequence2 = ts(:,121:end);
Here Subsequence1 will be 2000x30 and Subsequence2 will have the remaining elements of each row.

댓글 수: 9

Silpa K
Silpa K 2019년 11월 11일
It is not working in my code section.I need sequences ,every sequence contain 30 array points the remaining one is considering as next sequence.
clc
clear
b=zeros(175,1);
ts = xlsread('SwedishLeaf_TRAIN'.xlsx');
l=length(ts);
for i = 1:550
p=ts(i,:);
subSequence{1} = p(1:30);
subSequence{2} = p(31:60);
subSequence{3} = p(61:90);
subSequence{4} = p(91:120);
subSequence{5} = p(121:150);
subSequence{6} = p(151:180);
subSequence{7} = p(181:220);
subSequence{8} = p(220:250);
subSequence{9} = p(251:300);
subSequence{10} = p(301:end);
end
I tried this method for finding subsequence,but it is manually.How can I find subsequences.
Ajay Pattassery
Ajay Pattassery 2019년 11월 11일
편집: Ajay Pattassery 2019년 11월 11일
please post the error message you are getting when using
subsequence = (reshape(ts',30,[]))'
Note, the transpose operator " ' " used in the above code.
Also post the output of
size(ts)
Silpa K
Silpa K 2019년 11월 11일
If it is not divisible by 30,then how can I do this.
Silpa K
Silpa K 2019년 11월 11일
Using the above Iam getting errors like not divisible by 30 in some datasets.
Image Analyst
Image Analyst 2019년 11월 11일
So what would you LIKE to do when you have only a partial set (not the full 30)?
Silpa K
Silpa K 2019년 11월 11일
I need all subsequences,If a dataset row is not divisible by 30 ,then I need to take the remaining set also(every sequences)I need to apply this to each row.
Ajay Pattassery
Ajay Pattassery 2019년 11월 12일
1.So say your row comprises of 40 numbers ([1 2 . . . 40]), you want two subsequence.
Seq1 = [1 2 . . . 30] and Seq2 = [31 32 . . . 40], am I right?
2. You can not store the subsequence in a matrix as you were doing above since the subsequece length is not fixed. If the order of the subsequence does not matters you could try my second suggestion in the above answer. (Split the matrix into two, one with number of coulumns equals to mulitple of 30 and second matrix with remaining elements)
buffer() from the signal processing toolbox is useful. But otherwise mat2cell()
L = length(Ts1);
BL = 30;
if mod(L, BL)
Sequences = cell2mat(Ts1, 1, [BL * ones(1, floor(L/BL)), mod(L,BL)]);
else
Sequences = cell2mat(Ts1, 1, BL * ones(1, floor(L/BL)));
end
Silpa K
Silpa K 2019년 11월 12일
I used this in below code,Iam getting errors.Please help me
ts = xlsread('ArrowHead_TRAIN.xlsx');
l=length(ts);
for i = 1:24
p=ts(i,:)
fa = movstd(p,20,1);
secarray=movstd(fa,20,1) ;
k=maxk(secarray,10);
mpt=find(p);
mp=p(mpt(round(numel(mpt)/2)));
G=min(abs(mp-k));
[~,ii] = min(abs(p(:) - k(:)'));
out = p(unique(ii));
L = length(p);
BL = 30;
if mod(L, BL)
Sequences = cell2mat(p, 1, [BL * ones(1, floor(L/BL)), mod(L,BL)]);
else
Sequences = cell2mat(p, 1, BL * ones(1, floor(L/BL)));
end
A = [];
A = [];
for ii = 1:length(SubSequences)
if any(ismember(Subsequences,out))
if (k-mp<=G+l/2)
A{end+1} = Subsequences;
end
end
end
disp(aa);
Z=Subsequences;
idx = p(1:1);
q=[idx Z];
data = q;
cellReference = sprintf('A%d', i);
xlswrite('swetrain.xlsx', data, 1, cellReference);
end

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

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

질문:

2019년 11월 8일

댓글:

2019년 11월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by