필터 지우기
필터 지우기

I have a cell array (see picture). I want to fill those gaps by a number. How can i do this? I will really appreciate your help. Thanks

조회 수: 1 (최근 30일)
i tried this code. But it didn't work
for jj=1:r_txt-1
if isempty(DO_txt(jj));
DO_txt2{jj,1}={'0'};
end
end

답변 (1개)

Walter Roberson
Walter Roberson 2016년 10월 30일
mask = cellfun(@isempty, D0_txt(1:r_txt-1));
D0_txt2(mask) = {'0'};
  댓글 수: 3
Mohammad Abu Zafer Siddik
Mohammad Abu Zafer Siddik 2016년 10월 31일
My cell was blank. It doesn't have a cell like "[]". If the cell like "[]" then we can solve this by your code and mine. I don't really understand, what does that blank is? Is it an empty or anything else. I am confused. Thanks
Walter Roberson
Walter Roberson 2016년 10월 31일
Works for me, other than it coming out as a row vector by default:
D0_txt = cell(20,1);
D0_txt([3,7,13,19]) = {'10A'};
r_txt = 20;
mask = cellfun(@isempty, D0_txt(1:r_txt-1));
D0_txt2(mask) = {'0'};
>> D0_txt2
D0_txt2 =
1×18 cell array
'0' '0' [] '0' '0' '0' [] '0' '0' '0' '0' '0' [] '0' '0' '0' '0' '0'
Possibly your cells that look blank are not empty and hold blanks instead.
You might notice that the output includes [] . Those are at the positions where D0_txt was not empty. You did not define what the contents of D0_txt2 should be where D0_txt is not empty.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by