???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

 采纳的回答

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