PROBLEM WITH CREATION SUBSTRINGS IN ARRAY
1 回表示 (過去 30 日間)
古いコメントを表示
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
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!