FOR LOOP ERROR IN MATLAB
조회 수: 2 (최근 30일)
이전 댓글 표시
function states = markov_1(time, transmat)
format long
transmat = [0.9972 0.00022831; 0.5 0.5];
n = length(transmat);
states = zeros(1, n);
states(1)=1;
for i = 1:time
states = states * transmat;
end
댓글 수: 0
답변 (1개)
Sulaymon Eshkabilov
2021년 11월 10일
[for end] loop is working perfectly ok, but there is an error in your defined function's input arguments. See the corrections:
time =3;
transmat = [0.9972 0.00022831; 0.5 0.5];
markov_1(time, transmat)
function states = markov_1(time, transmat)
format long
%transmat = [0.9972 0.00022831; 0.5 0.5];
n = length(transmat);
states = zeros(1, n);
states(1)=1;
for i = 1:time
states = states * transmat;
end
end
댓글 수: 3
Walter Roberson
2021년 11월 10일
The code @Sulaymon Eshkabilov posted will already work for user-provided time, if you write the code to markov_1.m
function states = markov_1(time, transmat)
n = length(transmat);
states = zeros(1, n);
states(1)=1;
for i = 1:time
states = states * transmat;
end
end
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!