Array instead of one value in loop form
古いコメントを表示
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
2 件のコメント
Sindar
2020 年 10 月 15 日
first: "max" is an important function name, don't use it for variable names
What does it mean to use a vector for "max"? Do you want it to loop from one to each element of "max"? Or, do you want to loop over the elements of "max". If the latter, just do:
for i=not_calling_you_max
Image Analyst
2020 年 10 月 16 日
Same thing for "input" -- it's a built-in function.
I still have no idea what you want to do. Mainly because you forgot to put in crucial comments which all serious professional programmers like me put into their programs. Make it easy for us to help you not hard, by explaining what you want to do, not just overall in words, but by comments in your code.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Mathematics についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!