A number contain in a series.
1 次查看(过去 30 天)
显示 更早的评论
Silpa K
2019-9-19
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 个评论
Guillaume
2019-9-19
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.
回答(1 个)
thoughtGarden
2019-9-19
编辑:thoughtGarden
2019-9-20
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 个评论
Guillaume
2019-9-19
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))
Silpa K
2019-9-20
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
2019-9-20
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
2019-9-20
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.
thoughtGarden
2019-9-20
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
2019-9-20
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
2019-9-20
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
2019-9-20
for ii = 1:7
subSequence(ii,:) = s((ii-1)*30 + 1:ii*30);
end
getting error in this for .
thoughtGarden
2019-9-20
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
2019-9-20
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.
Silpa K
2019-9-20
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
2019-9-20
Conversion to cell from double is not possible.
Error in example (line 12)
subSequence(ii,:) = s((ii-1)*30 + 1:ii*30);
thoughtGarden
2019-9-20
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)
thoughtGarden
2019-9-20
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
2019-9-20
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
2019-9-20
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
2019-9-20
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
2019-9-20
[~,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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)