How to to write a code to my n*1 matrix into differnt submatrices?
Mostrar comentarios más antiguos
Hi guys, I have N*1 Index matrix with N rows. Where N varies for different files. My matrix consists N number of channels. I need to copy my channels into one group when difference between my channel is greater than one.I need to make differnt groups whenever differnce between the channels is greater than one. I tried to use Magic function and find function to save into different groups. When I use FIND function, I can find channels which difference are greater than one and less than one. I am unable to copy them into differnt groups.
Can anyone help me with this problem
Cheers,
Sudheer
Respuesta aceptada
Más respuestas (2)
Jan
el 3 de Mzo. de 2011
3 votos
It sounds like you need HIST or HISTC, especially the 2nd output argument.
1 comentario
sudheer kumar reddy
el 3 de Mzo. de 2011
Paulo Silva
el 3 de Mzo. de 2011
a=[164 165 166 167 175 176 177 189 190 195 196]';
b=diff(a); %find differences
idx=find(b>1); %find their indexes
idx=[idx;numel(a)]; %add the last value as index
cel=cell(1,numel(idx)); %make a cell to hold the groups
sv=1; %start value
for f=1:numel(idx)
cel{f}=a(sv:idx(f)); %take each part of a into a group
sv=idx(f)+1; %make the next start value
end
bar(cellfun(@mean,cel))
4 comentarios
Matt Fig
el 3 de Mzo. de 2011
This is a better solution, only calling FIND once and preserving the order.
You could get sv directly by:
idx = find(diff(A)~=1);
idx = [idx;length(A)];
sv = [1; idx(1:end-1)+1];
+1 vote
Paulo Silva
el 3 de Mzo. de 2011
Thanks Matt, your tips are always welcome :)
sudheer kumar reddy
el 3 de Mzo. de 2011
Paulo Silva
el 3 de Mzo. de 2011
cellfun(@mean,cel)
Categorías
Más información sobre Resizing and Reshaping Matrices en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!