フィルターのクリア

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?
  1 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 12 月 27 日
What is the expected result?

サインインしてコメントする。

採用された回答

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 Center および File ExchangeCharacters and Strings についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by