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

99 次查看(过去 30 天)
How can i replace the [] in the pathrisk field with 0's?
Thanks for your help!

采纳的回答

Mark
Mark 2014-1-15
编辑:Mark 2014-1-15
for i = 1:length(pathrisk)
if isempty(pathrisk(i))
pathrisk(i) = 0;
end
end

更多回答(1 个)

Jos (10584)
Jos (10584) 2014-1-15
编辑:Jos (10584) 2014-1-15
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 个评论

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by