I have a cell array (see picture). I want to fill those gaps by a number. How can i do this? I will really appreciate your help. Thanks
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Mohammad Abu Zafer Siddik
el 30 de Oct. de 2016
Comentada: Walter Roberson
el 31 de Oct. de 2016
i tried this code. But it didn't work
for jj=1:r_txt-1
if isempty(DO_txt(jj));
DO_txt2{jj,1}={'0'};
end
end
0 comentarios
Respuestas (1)
Walter Roberson
el 30 de Oct. de 2016
mask = cellfun(@isempty, D0_txt(1:r_txt-1));
D0_txt2(mask) = {'0'};
3 comentarios
Walter Roberson
el 31 de Oct. de 2016
Works for me, other than it coming out as a row vector by default:
D0_txt = cell(20,1);
D0_txt([3,7,13,19]) = {'10A'};
r_txt = 20;
mask = cellfun(@isempty, D0_txt(1:r_txt-1));
D0_txt2(mask) = {'0'};
>> D0_txt2
D0_txt2 =
1×18 cell array
'0' '0' [] '0' '0' '0' [] '0' '0' '0' '0' '0' [] '0' '0' '0' '0' '0'
Possibly your cells that look blank are not empty and hold blanks instead.
You might notice that the output includes [] . Those are at the positions where D0_txt was not empty. You did not define what the contents of D0_txt2 should be where D0_txt is not empty.
Ver también
Categorías
Más información sobre Characters and Strings 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!