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

80 ビュー (過去 30 日間)
Kenneth Morley
Kenneth Morley 2014 年 1 月 15 日
コメント済み: Ioannis Vourvachakis 2021 年 10 月 11 日
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 件のコメント
Kenneth Morley
Kenneth Morley 2014 年 1 月 15 日
THANK YOU!!!

サインインしてコメントする。

その他の回答 (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 件のコメント
Abdullateef Agbaje
Abdullateef Agbaje 2021 年 1 月 23 日
Thank you
Ioannis Vourvachakis
Ioannis Vourvachakis 2021 年 10 月 11 日
thank you so much!!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by