MATLAB Answers

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

486 views (last 30 days)
Kenneth Morley
Kenneth Morley on 15 Jan 2014
Commented: Abolfazl Nejatian on 27 Nov 2019
How can i replace the [] in the pathrisk field with 0's?
Thanks for your help!

  0 Comments

Sign in to comment.

Accepted Answer

Mark
Mark on 15 Jan 2014
Edited: Mark on 15 Jan 2014
for i = 1:length(pathrisk)
if isempty(pathrisk(i))
pathrisk(i) = 0;
end
end

More Answers (1)

Jos (10584)
Jos (10584) on 15 Jan 2014
Edited: Jos (10584) on 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

  1 Comment

Abolfazl Nejatian
Abolfazl Nejatian on 27 Nov 2019
Dear Jos,
your responce was very helpful for me.
thank you so much.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!