Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Split one column data into 4 arrays

2 visualizaciones (últimos 30 días)
Francisco Anaya
Francisco Anaya el 3 de Abr. de 2019
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
I have an array of 90872x1 double with 4 conditions. As follows:
A=
1
1
1
2
2
2
3
3
4
4
1
1
2
2
3
3
4
4
1
1
1
I want to split the vector into 4 arrays, one per condition. Each column of the new 4 arrays must contain de data of the conditions. Therefore.
A1=
1 1 1
1 1 1
1 1
A2=
2 2
2 2
2
A3=
3 3
3 3
A4=
4 4
4 4
Any help?
  3 comentarios
Francisco Anaya
Francisco Anaya el 3 de Abr. de 2019
I used the following and worked well...
[C,ia,ib]=unique(B); %groups
G=length(C);
iwant=cell(G,1);
for j=1:G
A=(B==C(j))';
jj=zeros(size(A));
ii=A==1;
jj(strfind([0,ii(:)'],[0 1]))=1;
idx=cumsum(jj).*ii;
iwant{j}=accumarray(idx(ii)',B(ii)',[],@(x){x'});
end
Walter Roberson
Walter Roberson el 3 de Abr. de 2019
That creates a cell array, but your question requires a numeric array as output.

Respuestas (1)

KSSV
KSSV el 3 de Abr. de 2019
A=[1
1
1
2
2
2
3
3
4
4
1
1
2
2
3
3
4
4
1
1
1] ;
C = unique(A) ;
iwant = cell(length(C),1) ;
for i = 1:length(C)
iwant{i} = A(A==C(i)) ;
end

La pregunta está cerrada.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by