Remove non-empty and zeroed cells from cell array.
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
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?
采纳的回答
Andrei Bobrov
2017-6-13
A = myArray';
[~,ii] = find(~cellfun(@isempty,A));
out = accumarray(ii,[A{:}]',[],@(x){x'})
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!