How do I replace [ ] in an array with 0's

 Respuesta aceptada

Mark
Mark el 15 de En. de 2014
Editada: Mark el 15 de En. de 2014
for i = 1:length(pathrisk)
if isempty(pathrisk(i))
pathrisk(i) = 0;
end
end

Más respuestas (1)

Jos (10584)
Jos (10584) el 15 de En. de 2014
Editada: Jos (10584) el 15 de En. de 2014
If I am not mistaken, the variable pathrisk is a cell array with some empty cells?
pathrisk = {1 [] 5 3 [] [] 9} % example data
tf = cellfun('isempty',pathrisk) % true for empty cells
pathrisk(tf) = {0} % replace by a cell with a zero

4 comentarios

Abolfazl Nejatian
Abolfazl Nejatian el 27 de Nov. de 2019
Dear Jos,
your responce was very helpful for me.
thank you so much.
Fernando Galaz Prieto
Fernando Galaz Prieto el 23 de Sept. de 2020
Upvoting!
Thank you very much.
Abdullateef Agbaje
Abdullateef Agbaje el 23 de En. de 2021
Thank you
Ioannis Vourvachakis
Ioannis Vourvachakis el 11 de Oct. de 2021
thank you so much!!

Iniciar sesión para comentar.

Categorías

Más información sobre Characters and Strings en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 15 de En. de 2014

Comentada:

el 11 de Oct. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by