A number contain in a series.

I have a series 's'
s=(1:1,2:end)
I find its subsequences like
a=s(1:30)
b=s(30:60)
c=s(60:90)
d=s(90:120)
e=s(120:150)
f=s(150:180)
j=s(180:210)
h=s(210:250)
and I have a set of points 'k'.
I need to check any of the subsequence contain any points of the K.If it contain I need to add those subsequence into a variable 'A'.How can I do this.Please help me.

1 Kommentar

s = (1:1, 2:end)
is not valid matlab syntax. So, the first problem with your question is we don't really not what your series is.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

thoughtGarden
thoughtGarden am 19 Sep. 2019
Bearbeitet: thoughtGarden am 20 Sep. 2019

0 Stimmen

You haven't provided enough information to be certain of what you want, but makeing some assumptions, this should work.
clear;clc;
% "series" s, which is an array
s = 1:1:250;
% Build "subsequences"
for ii = 1:7
subSequence(ii,:) = s((ii-1)*30 + 1:ii*30);
end
% Build "set of points 'k'"
k = randi(1000,1,10);
% A will contain all subsequences that contain any of the values of k
A = [];
% In each loop, determine if there is any overlap betweent he subsequence
% and the variable k. If there is, add the subsequency to the variable A.
% Otherwise, move on to the next subsequence.
for ii = 1:length(subSequence(:,1))
if(intersect(subSequence(ii,:),k))
A(end+1,:) = subSequence(ii,:);
else
%do nothing...
end
end
% Disp A, which in the case of this script might be empty as k is random
% values...
disp(A)
This builds an array containing all the subsequences that contain any values found in k. If that is what you are looking for, this works.

23 Kommentare

Note that
if intersect(subSequence{ii},k) %no need for extra brackets
would be better written as
if ~isempty(intersect(subSequence{ii},k))
as that's what your if expression will evaluate to and I think what you meant. In particular your if will be false if the intersection is the vector [0].
Even better would be to use ismember as you don't actually care about computing the intersection:
if any(ismember(subSequence{ii}, k))
thoughtGarden
thoughtGarden am 19 Sep. 2019
You are correct on all accounts. Answer updated.
Silpa K
Silpa K am 20 Sep. 2019
Iam getting 0×0 empty cell array.But actually k points is in the subsequence.
Silpa K
Silpa K am 20 Sep. 2019
d = xlsread('FaceFour_TRAIN.xlsx')
s = d(1:1,2:end );
fa = movstd(s,20 );
secarray = movstd(fa,20 ) ;
sec = secarray(secarray>.04 );
k=maxk(sec,14);
a=s(1:30)
b=s(30:60)
c=s(60:90)
d=s(90:120)
e=s(120:150)
f=s(150:180)
j=s(180:210)
Silpa K
Silpa K am 20 Sep. 2019
If I need to display the nearest value and the subsequence that contain in a series.How can I do that,please help someone.
Guillaume
Guillaume am 20 Sep. 2019
the nearest value
the value of what nearest to the value of what?
thoughtGarden() has shown you an efficient way of storing the subsequences, using indices of a cell array. Using sequentially named variables (a, b, c, ...) as you have done is an extremely bad way of writing code. Use indexing instead.
After looking at your code, it looks like you are trying to find the subsequences that contain any of the max 14 values of the variable sec. If you use the template above (note I removed the cells as it appears you have constant and equal length subsequences) you can solve the problem. I have not used your sequencial lettering of variables because in general this is poor practice (what if you your subsequence number grows in the future?). However, if k is some array containing values that are also present in the subsequences, the for loop will find them.
d = xlsread('FaceFour_TRAIN.xlsx')
s = d(1:1,2:end );
fa = movstd(s,20 );
secarray = movstd(fa,20 ) ;
sec = secarray(secarray>.04 );
k=maxk(sec,14);
% Build "subsequences"
for ii = 1:7
subSequence(ii,:) = s((ii-1)*30 + 1:ii*30);
end
% A will contain all subsequences that contain any of the values of k
A = [];
% In each loop, determine if there is any overlap betweent he subsequence
% and the variable k. If there is, add the subsequency to the variable A.
% Otherwise, move on to the next subsequence.
for ii = 1:length(subSequence(:,1))
if(intersect(subSequence(ii,:),k))
A(end+1,:) = subSequence(ii,:);
else
%do nothing...
end
end
% Disp A, which in the case of this script might be empty as k is random
% values...
disp(A)
Pending you are reading the excel file correctly, this should work.
Silpa K
Silpa K am 20 Sep. 2019
Ok.I have a doubt ,How can I display the subSequence which contain the points,like
W=subsequence{1},subsequence{4}
W are the subSequences that contain the any of the points.
thoughtGarden
thoughtGarden am 20 Sep. 2019
A has as many rows as subsequences that contained data found in k. If 3 subsequences contain data found in k, then A has 3 rows. A thus holds all the subsequences of interest. I'm not sure what the variable W is, but I think all you want (according to your OP) is A.
Silpa K
Silpa K am 20 Sep. 2019
for ii = 1:7
subSequence(ii,:) = s((ii-1)*30 + 1:ii*30);
end
getting error in this for .
thoughtGarden
thoughtGarden am 20 Sep. 2019
What is the error? How big is s? you previously indicated that s has 250 elements and then 210. If either of these values are valid, you should see no issue.
Silpa K
Silpa K am 20 Sep. 2019
The s values are valid.Only some data set may change 252 or 210 like.But all the values are valid.Error showing
subSequence(ii,:) = s((ii-1)*30 + 1:ii*30);
in this line.
thoughtGarden
thoughtGarden am 20 Sep. 2019
Please copy and past the error.
Silpa K
Silpa K am 20 Sep. 2019
A has as many rows as subsequences that contained data found in k. If 3 subsequences contain data found in k, then A has 3 rows. A thus holds all the subsequences of interest. I'm not sure what the variable W is, but I think all you want (according to your OP) is A.
Depending on this answer,
Sir I want to display the sequence names that contain the points.
Silpa K
Silpa K am 20 Sep. 2019
Conversion to cell from double is not possible.
Error in example (line 12)
subSequence(ii,:) = s((ii-1)*30 + 1:ii*30);
Silpa K
Silpa K am 20 Sep. 2019
This is my data set.
See my comment above. I switched from cells to data array as it appeared you didn't need the extra overhead of cells as each subsequence is the same length.
d = xlsread('FaceFour_TRAIN.xlsx')
s = d(1:1,2:end );
fa = movstd(s,20 );
secarray = movstd(fa,20 ) ;
sec = secarray(secarray>.04 );
k=maxk(sec,14);
% Build "subsequences"
for ii = 1:7
subSequence(ii,:) = s((ii-1)*30 + 1:ii*30);
end
% A will contain all subsequences that contain any of the values of k
A = [];
% In each loop, determine if there is any overlap betweent he subsequence
% and the variable k. If there is, add the subsequency to the variable A.
% Otherwise, move on to the next subsequence.
for ii = 1:length(subSequence(:,1))
if(intersect(subSequence(ii,:),k))
A(end+1,:) = subSequence(ii,:);
else
%do nothing...
end
end
% Disp A, which in the case of this script might be empty as k is random
% values...
disp(A)
The code in my just previous comment throws no errors (I just ran it with your data set). However, k doesn't have any overlapping values with any of your subsequences:
k =
Columns 1 through 10
0.4889 0.4823 0.4815 0.4719 0.4705 0.4577 0.4553 0.4393 0.4341 0.4175
Columns 11 through 14
0.4037 0.4035 0.4015 0.3986
and your subsequences are all whole numbers, thus no overlap. Did you intend your subsequences to have only whole nubmers? Did you indend k to have only whole numbers? This discrempancy must be resolved before more progress can be made.
Silpa K
Silpa K am 20 Sep. 2019
I need to find any of of the k present any of the subsequence .If any subsequence contain any of the k values then showing that subsequence.
thoughtGarden
thoughtGarden am 20 Sep. 2019
Right, but no values in k are present int he subsequence you've indicated. The subsequences you have provided are all whole numbers, but the values in k are not. Thus there is no overlap between any value in k and any subsequence. You either need different k or different subsequence.
Silpa K
Silpa K am 20 Sep. 2019
I used different k value that contain in the series s,then also getting an error
Conversion to cell from double is not possible.
Error in example (line 10)
subSequence(ii,:) = s((ii-1)*30 + 1:ii*30);
Silpa K
Silpa K am 20 Sep. 2019
I need to display the subsequence name that contain k.
Silpa K
Silpa K am 20 Sep. 2019
[~,ii] = min(abs(s(:) - k(:)'));
out = s(unique(ii));
using this I get nearest elements,now also I can't getting the name of the subsequence

Melden Sie sich an, um zu kommentieren.

Kategorien

Tags

Gefragt:

am 19 Sep. 2019

Kommentiert:

am 20 Sep. 2019

Community Treasure Hunt

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

Start Hunting!

Translated by