現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
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 日
Iam getting 0×0 empty cell array.But actually k points is in the subsequence.
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 で Entering Commands についてさらに検索
タグ
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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 (한국어)