???index exceeds matrix dimensions

in my program i have used for loop and if loop at the end i am getting ???index exceeds matrix dimensions this comment after calculating 1 value, where i have to calculate 42 values i used
example
for x=1:42
if x==1
a=1;
b=2;
end
if x==2
a=2;
b=3;
end
:
:
:
:
:
:
if x==42
a=42;
b=43;
end
c=a+b
end

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2011년 11월 22일

0 개 추천

x=1:42
c = 2*x+1
more :)
c = zeros(1,42);
for x = 1:42
a = x;
b = a + 1;
c(x) = a + b;
end
more 2
x=1:42
c = zeros(size(x));
for i1 = 1:numel(x)
if x(i1) == i1
a = x(i1);
b = a + 1;
end
c(i1) = a + b;
end

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by