필터 지우기
필터 지우기

PROBLEM WITH CREATION SUBSTRINGS IN ARRAY

조회 수: 1 (최근 30일)
FRANCISCO
FRANCISCO 2013년 12월 27일
편집: Azzi Abdelmalek 2013년 12월 27일
Very good, I, for example I have a string like this:
s = [0 1 0 0]
and I use the following code for creating substring length = 3
if true
% code
n=3;
m=numel(s)-n+1;
A=zeros(m,n);
idx=cell2mat(arrayfun(@(x) x : x+n-1,(1:m)','un',0));
out=s(idx);
[a,b,c]=unique(out,'rows','stable');
end
The substrings are created as follows:
s = [0 (1) 1 (2) 0 (3) 0 (4)]
1-0 (1) 1 (2) 0 (3)
2-1 (2) 0 (3) 0 (4)
The substrings are always created in this way.
The problem arises when I want to calculate the substrings in an array:
s = [0 1 0 0; 1 1 0 0]
How I can do?

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 12월 27일
편집: Azzi Abdelmalek 2013년 12월 27일
s = [0 1 0 0; 1 1 0 0]
n=3;
m=size(s,2)-n+1;
idx=cell2mat(arrayfun(@(x) x : x+n-1,(1:m)','un',0));
M=[];
for k=1:size(s,1)
ss=s(k,:);
M=[M; ss(idx)];
end
M=unique(M,'rows','stable')

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by