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!