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

 Risposta accettata

Mark
Mark il 15 Gen 2014
Modificato: Mark il 15 Gen 2014
for i = 1:length(pathrisk)
if isempty(pathrisk(i))
pathrisk(i) = 0;
end
end

Più risposte (1)

Jos (10584)
Jos (10584) il 15 Gen 2014
Modificato: Jos (10584) il 15 Gen 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 Commenti

Dear Jos,
your responce was very helpful for me.
thank you so much.
Upvoting!
Thank you very much.
thank you so much!!

Accedi per commentare.

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by