Azzera filtri
Azzera filtri

How to add NaN in cell before last one

1 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

KSSV
KSSV il 17 Dic 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

Più risposte (0)

Categorie

Scopri di più su Numeric Types in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by