Filter löschen
Filter löschen

PROBLEM WITH CREATION SUBSTRINGS IN ARRAY

3 Ansichten (letzte 30 Tage)
FRANCISCO
FRANCISCO am 27 Dez. 2013
Bearbeitet: Azzi Abdelmalek am 27 Dez. 2013
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?

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 27 Dez. 2013
Bearbeitet: Azzi Abdelmalek am 27 Dez. 2013
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')

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by