MATLAB: Could anyone help me how to overcome the error in the following code

non-singleton rhs dimensions

code:
a=[2 4 6 8 ]
b=[12]
for it=1
for t = 1:length(a)
for r = 1:length(b)
c=1:a(t)
for s=1:numel(c)
o_th{t,r,s}=1.2442e+12
iwant1(t,r,s) = sum(cell2mat(o_th(t,r,s,:)))
iwant2=max(iwant1,[],3)
iwant12(:,:,it)=iwant2
end
end
end
end
IF i run the code i am getting error stating Assignment has more non-singleton rhs dimensions than non-singleton subscripts
Error in iwant12(:,:,it)=iwant2.
could anyone help me on this.

Best Answer

You have not declared iwant12 yet so that when you say you want all rows and all columns in the it'th plane,
iwant12(:,:,it)=iwant2
it doesn't know how many rows and columns there are because you do not have iwant12 yet - it doesn't know the size yet.