Remove non-empty and zeroed cells from cell array.

hey
i have cell array like this:
myArray= {[],1,1,0.1,0.1;[],[],1,1,0.2;[],[],[],[],1;0.3,[],[],[],0.6;0.4,[],[],0.3 [];0.6,0.33,0.12,0.67,0.13;1,0.62,0.11,0.31,1;[],[],[],1,[]}
how to remove empty and zeroed cells from this array for each row. i have tried following which worked fine if i apply it on each row separately. but how to do it for whole array.
newArray=reshape(myArray(~cellfun(@isempty,myArray)),1,[]);
Thanks

3 件のコメント

Geoff Hayes
Geoff Hayes 2017 年 6 月 13 日
lucksBi - since this is a two-dimensional cell array, what do you expect the output to be especially if you remove more elements from one row than the other? Some rows will have fewer columns and so you will not be able to combine all rows into a single matrix. Do you wish to create another cell array where each element is the modified row from myArray?
Matt J
Matt J 2017 年 6 月 13 日
how to remove empty and zeroed cells from this array for each row
Doing so would result in rows of different lengths. What do you want to replace the cells with so that it can maintain its rectangular shape?
lucksBi
lucksBi 2017 年 6 月 13 日
Can i get it in a cell array in which each cell contains non-zero elements from each row?

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

 採用された回答

Andrei Bobrov
Andrei Bobrov 2017 年 6 月 13 日

1 投票

A = myArray';
[~,ii] = find(~cellfun(@isempty,A));
out = accumarray(ii,[A{:}]',[],@(x){x'})

1 件のコメント

lucksBi
lucksBi 2017 年 6 月 13 日
Thank You this is accurate.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData Types についてさらに検索

タグ

質問済み:

2017 年 6 月 13 日

コメント済み:

2017 年 6 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by