replacing blank values in a single column cell array with the previous value

6 ビュー (過去 30 日間)
Michael
Michael 2011 年 5 月 19 日
basically i have a list of values in a cell array.
A =
'-2.0372681e-10'
'0'
'-1.1641532e-10'
'-2.910383e-11'
'&nbsp'
'&nbsp'
'-1.45579e-11'
'0'
'&nbsp'
'2.9103759e-11'
'&nbsp'
'1.455188e-11'
'-2.910383e-11'
'7.2759396e-11'
'-1.45579e-11'
'2.9103759e-11'
'-4.3655746e-11'
'8.7311276e-11'
I want all the blanks to be filled with whatever the previous cell value is
  1 件のコメント
Sean de Wolski
Sean de Wolski 2011 年 5 月 19 日
What do you want to do if the first entry is blank?

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

採用された回答

Andy
Andy 2011 年 5 月 19 日
Pending the answer to Sean de's comment, I will assume the first entry is not blank:
for ix=2:length(A)
if isempty(A{ix})
A{ix} = A{ix-1};
end
end
EDIT: As per Sean de's suggestion, the for loop now starts at 2. Michael, you may have to adjust this if the first element is allowed to be blank. (The code will not cause an error, but the result will not be what you intended.)
  1 件のコメント
Sean de Wolski
Sean de Wolski 2011 年 5 月 19 日
This is probably just as good as any vectorized solution since we're dealing with cell arrays. +1!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by