MATLAB: Array instead of one value in loop form

MATLABmax

How can I use this code if max = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27] instad of max = 27.
Some one can please help me with this code thank you..
clear all
close all
clc
max =27;
%max=[ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27]; I want to use this instead of max= 27 for same code
k=0;
s=0;
c=0;
flag=1;
state(1)=0;
% initialinput=0
% tempin=initialinput
% input= randi([0 1],1,max)
input=[ 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 0];
initialinput=input(1);
output=input;
for i=1:max
if(i==1)
if(input(i)==initialinput)
state(i)=state(1);
seq(i)=s;
% s=s+1;
if(flag>1 && flag <= 9)
number=k;
integ=floor(number);
k=integ;
k=k+(2^(flag))/1000;
t(i)=k;
flag=flag+1;
else
k=k+1;
t(i)=k;
end
end
elseif(input(i)==input(i-1))
state(i)=state(i-1);
s=s+1;
seq(i)=s;
if(flag>1 && flag <= 9)
number=k;
integ=floor(number);
k=integ;
% fract=number-integ;
k=k+(2^(flag))/1000;
t(i)=k;
flag=flag+1;
else
k=k+1;
t(i)=k;
end
elseif(input(i)~=input(i-1))
state(i)=state(i-1)+1;
seq(i)=0;
s=0;
if(c==0)
flag=1;
end
number=k;
integ=floor(number);
k=integ;
k=k+1;
t(i)=k;
c=0;
%
flag=flag+1;
end
end

Best Answer

I assume that you want to iterate over the loop for the 27 values, i=[1,2,3,...,27]. That is exactly what for i=1:27 does. (The loop for i=[1,2,3,...,27] also does that.)
The loop for i=1:[1,2,3,...,27] on the contrary runs the loop only for the value i=1. I tested on R2018b. I think Matlab should have issued a warning.
With max=27 your code produces
>> state
state =
Columns 1 through 24
0 0 0 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 3 3 3 3 4 4
Columns 25 through 27
4 4 4