MATLAB: Replacing empty cells using for loop

cell arrays

Hi there, I have 796×1 cell array consisting of 1×1 scalar arrays, or empty arrays. E.g.
>> ses1_results = {1.192;0;0;0;0.5678;0;0;0;0;0;0;1;[];1}
ses1_results =
14×1 cell array
{[ 1.1920]}
{[ 0]}
{[ 0]}
{[ 0]}
{[ 0.5678]}
{[ 0]}
{[ 0]}
{[ 0]}
{[ 0]}
{[ 0]}
{[ 0]}
{[ 1]}
{0×0 double}
{[ 1]}
The spacing of the 0s is irregular
I need to remove all the cells with 0, whilst maintaining the 0x0 cells and the values>0, and then convert that into an array. How can I do this? I've spent a few hours trying to do it like this but can't seem to figure it out:
Rxtcell = ses1_results(5:800,6);
for n = 1:796
Z = []
Q = 0
x = Rxtcell(n)
if 1 == strcmp(x,Q)
Rxtcell{n}=[999];
elseif 1== strcmp(x,Z)
Rxtcell(n)= [0];
else
end
end
RxTa = cell2mat(Rxtcell)

Best Answer

Short answer is, "you can't".
A double array cannot have an empty element; it is either empty or full.
A cell array is the only way in which I see you can do this other than, perhaps you could cobble something together with sparse maybe???
The only alternative I see in an ordinary array would be to replace the empty cell with NaN or some other indicator value.
ses1_results{cellfun(@isempty,ses1_results)}=nan;
res=cell2mat(ses1_results);
res(res==0)=[];
returns
res =
1.1920
0.5678
1.0000
NaN
1.0000
>>
Or, of course, following the comment; you've already got a cell array; just remove the cells that are zero.
>> ses1_results(~cellfun(@(v)isequal(v,0),ses1_results))
ans =
5×1 cell array
{[ 1.1920]}
{[ 0.5678]}
{[ 1]}
{0×0 double}
{[ 1]}
>>