Borrar filtros
Borrar filtros

How to add NaN in cell before last one

1 visualización (últimos 30 días)
haitham qutaiba
haitham qutaiba el 17 de Dic. de 2019
Comentada: haitham qutaiba el 17 de Dic. de 2019
Dear all,
i have a cell with different sizes
a{1} = [1 2 3 4 5 10];
a{2} = [2 2 4 5 10];
a{3} = [8 2 10];
a{4} = [8 2 9 9 2 1 3 10];
one row, 4 columns,
number 10 represent (label or number of class) of each one,
v = cellfun('size',a,2);
r = numel(a);
M = NaN(r,max(v));
for k = 1:r
M(k,1:v(k)) = a{k};
end
this for loop to find max and make the cell equal before change it to matrix, the problem is NaN added after last number which 10,
M =
1 2 3 4 5 10 NaN NaN
2 2 4 5 10 NaN NaN NaN
8 2 10 NaN NaN NaN NaN NaN
8 2 9 9 2 1 3 10
is there a way to add NaN before label 10 and make it equal as well?
thanks in advnace

Respuesta aceptada

KSSV
KSSV el 17 de Dic. de 2019
a{1} = [1 2 3 4 5 10];
a{2} = [2 2 4 5 10];
a{3} = [8 2 10];
a{4} = [8 2 9 9 2 1 3 10];
v = cellfun('size',a,2);
r = numel(a);
M = NaN(r,max(v));
for k = 1:r
M(k,1:v(k)-1) = a{k}(1:end-1);
M(k,end) = a{k}(end) ;
end

Más respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by