필터 지우기
필터 지우기

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

조회 수: 112 (최근 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개)

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 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