Index exceeds matrix dimensions error

1 view (last 30 days)
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.

Accepted Answer

Stijn Haenen
Stijn Haenen on 12 Jan 2020
Edited: Stijn Haenen on 12 Jan 2020
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

More Answers (0)

Community Treasure Hunt

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

Start Hunting!