Borrar filtros
Borrar filtros

PROBLEM WITH CREATION SUBSTRINGS IN ARRAY

1 visualización (últimos 30 días)
FRANCISCO
FRANCISCO el 27 de Dic. de 2013
Editada: Azzi Abdelmalek el 27 de Dic. de 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?

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 27 de Dic. de 2013
Editada: Azzi Abdelmalek el 27 de Dic. de 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')

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by