Problem to display output
2 ビュー (過去 30 日間)
古いコメントを表示
Hi, I have a problem to display the output. Can someone help me to solve this? Thanks a lots!
Below here are the codes:
for i = 1:3
trans_matrix = trans_matrix + diag(ones(N-i,1),i);
end
for n = 1: length(ladder_Start)
b = trans_matrix(:,ladder_End(n));
trans_matrix(:,ladder_End(n)) = trans_matrix(:,ladder_Start(n)) + b;
trans_matrix(:,ladder_Start(n)) = zeros(1,N);
b = [];
end
for n = 1: length(snake_Head)
b = trans_matrix(:,snake_Tail(n));
trans_matrix(:,snake_Tail(n)) = trans_matrix(:,snake_Head(n)) + b;
trans_matrix(:,snake_Head(n)) = zeros(1,N);
b = [];
end
b = trans_matrix;
trans_matrix = (1/3)*b;
b = [];
ITERATIONS = 200;
d=zeros(1,ITERATIONS);
for i = 1:200
b = trans_matrix^i;
d(i) = b(N+1,1);
end
b=[];
At the command window there it shows the error of this.

2 件のコメント
Mathieu NOE
2021 年 12 月 13 日
hello
some info's are missing like :
how is initilaized trans_matrix, ladder_Start,snake_Head
回答 (1 件)
Rik
2021 年 12 月 13 日
You're trying to index b. So let's explore the values involved:
%rest of your code
for i = 1:200
b = trans_matrix^i;
disp(b)
disp(N+1)
d(i) = b(N+1,1);
end
So you have a 25x25 matrix, and you try to get the first value from the 26th row. It doesn't exist, so Matlab throws the error.
Since you didn't include any comments in your code and used obfuscating names like b and d as variable names, it is impossible to understand what is happening or what the intended function was. It is therefore extremely difficult to suggest a change in your code.
v000=zeros(25,25);v001=[3, 9, 17];v002=[7, 18, 24];v003=[16, 20, 23];v004=...
[5, 12, 19];v005=25;for v006=1:3,v000=v000 + diag(ones(v005-v006,1),v006);
end,for v007=1: length(v001),v008=v000(:,v002(v007));v000(:,v002(v007))=...
v000(:,v001(v007)) + v008;v000(:,v001(v007))=zeros(1,v005);v008=[];end,for ...
v007=1: length(v003),v008=v000(:,v004(v007));v000(:,v004(v007))=v000(:,...
v003(v007)) + v008;v000(:,v003(v007))=zeros(1,v005);v008=[];end,v008=v000;
v000=(1/3)*v008;v008=[];v009=200;v010=zeros(1,v009);for v006=1:200,v008=...
v000^v006;v010(v006)=v008(v005+1,1);end,v008=[];
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!