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

80 vues (au cours des 30 derniers jours)
Kenneth Morley
Kenneth Morley le 15 Jan 2014
How can i replace the [] in the pathrisk field with 0's?
Thanks for your help!

Réponse acceptée

Mark
Mark le 15 Jan 2014
Modifié(e) : Mark le 15 Jan 2014
for i = 1:length(pathrisk)
if isempty(pathrisk(i))
pathrisk(i) = 0;
end
end

Plus de réponses (1)

Jos (10584)
Jos (10584) le 15 Jan 2014
Modifié(e) : Jos (10584) le 15 Jan 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 commentaires
Abdullateef Agbaje
Abdullateef Agbaje le 23 Jan 2021
Thank you
Ioannis Vourvachakis
Ioannis Vourvachakis le 11 Oct 2021
thank you so much!!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by