How to determine Empty matrix: 0-by-1 in a cell??

I have a cell of size 24x1. It is of the form k1 =
[ 13]
[ 13]
[ 13]
[ 13]
[ 13]
[ 13]
[ 0]
[ 12]
[ 12]
[0x1 double]
[ 12]
[ 12]
[ 12]
[ 11]
[ 11]
[ 11]
[ 11]
[ 11]
[ 11]
[ 9]
[0x1 double]
[ 10]
[ 10]
[ 10]
I want to detect the Empty Matrix: 0-by-1 cells in k1. For example, at k1(10), the value is [0x1 double]. I want to convert k1 into matrix and replace these empty matrices([0x1 double]) with zero. How can i do this?

 採用された回答

José-Luis
José-Luis 2013 年 5 月 23 日
編集済み: José-Luis 2013 年 5 月 23 日

0 投票

bla = {1:3,[],4}
your_logical_result = cellfun(@(x) isempty(x),bla)
bla(your_logical_result) = {0}

4 件のコメント

Divya
Divya 2013 年 5 月 23 日
Thank you. Its working
Jan
Jan 2013 年 5 月 23 日
Anonymous functions inside cellfun are slower than function handles. When cellfun has a corresponding built-in command (unfortunately they appear as "backward compatibility" in the docs only), they are massively faster:
cellfun(@isempty, bla); % faster
cellfun('isempty', bla); % fastest
José-Luis
José-Luis 2013 年 5 月 23 日
Thanks, good to know. Not very intuitive if you ask me.
Divya
Divya 2013 年 5 月 23 日
Thanks for the info

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by