# How to assign the first element of each cell in a cell aray using a matrix

2 visualizaciones (últimos 30 días)
xiaojuezi el 23 de Ag. de 2022
Respondida: David Hill el 23 de Ag. de 2022
Hi
I have a cell array A with size m x n, where each cell contains a vector of random size. Now I would like to assign the first element of a cell using a matrix B of size m x n. I tried with
B = num2cell(B);
A{:,1} = B{:};
However, the complier complains that "Consider using comma-separated list assignment.".
Is there a way to achieve this goal?
Thank you very much!
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Respuestas (1)

David Hill el 23 de Ag. de 2022
for k=1:10
for m=1:20
A{k,m}=randi(10,1,randi(15));%generate sample A cell array
end
end
B=zeros(size(A));
for k=1:numel(A)
B(k)=A{k}(1);%assign first element of arrays in A to B.
end
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

R2021b

### Community Treasure Hunt

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

Start Hunting!

Translated by