이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
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 (한국어)