# Math Help - matlab for loops?

1. ## matlab for loops?

So far i have this

VEC = input('Please type a value that is > 9 and < 21:')
if VEC < 10 || VEC > 21
error('Incorrect Input... Quitting!')
Vec1 = input('Type in a value for the first element:')

But not sure if I'm on the right track.. Could someone help me with this problem

2. Originally Posted by Mathhelpz

So far i have this

VEC = input('Please type a value that is > 9 and < 21:')
if VEC < 10 || VEC > 21
error('Incorrect Input... Quitting!')
Vec1 = input('Type in a value for the first element:')

But not sure if I'm on the right track.. Could someone help me with this problem
Have you tested it?

CB

3. yea,

this is my script so far

% initialize the vector
VEC = [];
n = 1;

VEC_length = input('Please type a value that is > 9 and < 21:');
if VEC_length < 10 || VEC_length > 21
error('Incorrect Input... Quitting!')
end

Vec1 = input('Type in a value for the first element:')

% Add first element to the vector
VEC(n)=Vec1;

% Use a for loop to add more number to the vector
for i=1:VEC_length
n=n+1;
VEC(n)= Vec1 +i;
end

I don't really know what to do on step 4? COuld you help me

4. Originally Posted by Mathhelpz
yea,

this is my script so far

% initialize the vector
VEC = [];
n = 1;

VEC_length = input('Please type a value that is > 9 and < 21:');
if VEC_length < 10 || VEC_length > 21
error('Incorrect Input... Quitting!')
end

Vec1 = input('Type in a value for the first element:')

% Add first element to the vector
VEC(n)=Vec1;

% Use a for loop to add more number to the vector
for i=1:VEC_length
n=n+1;
VEC(n)= Vec1 +i;
end

I don't really know what to do on step 4? COuld you help me
This is wrong:

Code:
VEC_length = input('Please type a value that is > 9 and < 21:');
if VEC_length < 10 || VEC_length > 21
error('Incorrect Input... Quitting!')
end
Try inputting a value of 21

CB

5. Originally Posted by Mathhelpz

I don't really know what to do on step 4? COuld you help me
Code:
if VEC(1)>=25
VEC(1)=0;
end

for k=2:VEC_LENGTH
VEC(k)=VEC(k-1)+1;
if VEC(k)>=25
VEC(k)=0;
end
end
CB

6. thanks for that, i almost finised it =D