MATLAB: Index exceeds matrix dimensions error

index exceeds matrix dimensions

hi. plz help me to fix this error.
t{1}=0;
for n=1:10
if n/2>2
t{n}=t{n}+1
end
end
% error: Index exceeds matrix dimensions.

Best Answer

You should use ( and ) not { and }.
Try this code:
t=zeros(10,1);
for n=1:10
if n/2>2
t(n)=t(n-1)+1
end
end
Related Question