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

 Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 22 Nov 2011

0 votes

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

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by