FOR LOOP ERROR IN MATLAB

조회 수: 2 (최근 30일)
Matthew Igbinehi
Matthew Igbinehi 2021년 11월 9일
댓글: Matthew Igbinehi 2021년 11월 10일
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

답변 (1개)

Sulaymon Eshkabilov
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
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
Matthew Igbinehi
Matthew Igbinehi 2021년 11월 10일
Thanks a lot, it is working now

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by