Deleting Empty Rows in Cell Array

1 回表示 (過去 30 日間)
tinkyminky93
tinkyminky93 2022 年 6 月 6 日
コメント済み: Fangjun Jiang 2022 年 6 月 7 日
Hello,
I have a cell array like
' '
' '
'1231231'
' '
' '
'1231231'
' '
I want to delete this blank elements and transform this cell array from 7x1 to 2x1. How can I do it? Is there any methods to solve this problem without cellfun or etc.? Thank you.

採用された回答

Fangjun Jiang
Fangjun Jiang 2022 年 6 月 6 日
If the data is in a cell array, mostly likely cellfun() is needed, unless you use for-loop.
strtrim() or strip() can remove the white spaces.
b={' '
' '
'1231231'
' '
' '
'1231231'
' '};
c=strip(b);
index=cellfun(@isempty,c);
d=b(~index)
d = 2×1 cell array
{'1231231'} {'1231231'}
  7 件のコメント
tinkyminky93
tinkyminky93 2022 年 6 月 7 日
@Fangjun Jiang sir I applied your suggestion and it seems like that is what I want. But I have a problem. My data becomes 32x1 cell and every element is 2x1 cell. What I want is 32x1 and every element is 1x2. How can I do it?
Fangjun Jiang
Fangjun Jiang 2022 年 6 月 7 日
Provide some example data that others can use directly in MATLAB to help you. For example
' '
'1231231'
can not be used directly in MATLAB, while
a={' '
'1231231'}
can so others can use it to provide you with example code.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by