A number contain in a series.

조회 수: 2 (최근 30일)
Silpa K
Silpa K 2019년 9월 19일
댓글: Silpa K 2019년 9월 20일
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
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
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
Silpa K
Silpa K 2019년 9월 20일
I need to display the subsequence name that contain k.
Silpa K
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 CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by