# How to concatenate elements of a cell array

1 visualización (últimos 30 días)
Arlinda Gashi el 10 de Jul. de 2021
Comentada: Arlinda Gashi el 10 de Jul. de 2021
I have a cell array containing 61 cells of 30 second audio data: stimuli = {1,1 1,2 1,3...}. I want to concatenate the cells i.e cell 1 and 2, 3 and 4... and so on, so at the end I have cells of 60 seconds data.
I tried the following code, but it does not work! I'd appreciate your help! Thank you!
stimdata = cell(1,31);
for i=size(stimuli,2)-1
stimdata{i} = stimuli{1,i},stimuli{1,i}+1
cnt = cnt+2;
end
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

LO el 10 de Jul. de 2021
Editada: LO el 10 de Jul. de 2021
if your cells are all of the same size, try using cell2mat (to convert your cell into array) and then reshape (to change the size from 60x30 to 30 x 60, assuming each half stimulus will have to be paired to the consecutive row)
You code contains errors, see if this helps (it would be useful to have your stimuli variable as well to troubleshoot
stimdata = cell(1,31);
for i= 1:2:size(stimuli,2)-1 % skip even numbers
if abs(i - size(stimuli,2)) >=2 % this should check if you have enough free stimuli to select two in a row
stimdata{i} = [stimuli{1,i},stimuli{1,i+1}]; % pair odd and even stimuli
cnt = cnt+2; % not sure why you want this one here
else
stimdata{i} = [stimuli{1,i}]; % pair odd and even stimuli
end
end
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Arlinda Gashi el 10 de Jul. de 2021
Many thanks! Your code solved the problem!

Iniciar sesión para comentar.

### Categorías

Más información sobre Audio and Video Data en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by