problem to implement an algorithm

I want to implement the algorithm in matlab but what I underlined with red is confusing me a little bit.
Is there a function in matlab that does this action, or do I just type path(i,j) and it will add on its own?

댓글 수: 4

John D'Errico
John D'Errico 2020년 12월 24일
Um, be careful? path is itself a function in MATLAB, that you do need. so naming a variable path can have consequences. Nor can you just assume that path(i,j) will do anything that you would expect it to do.
Khalid Sherif
Khalid Sherif 2020년 12월 24일
편집: Khalid Sherif 2020년 12월 24일
I will be naming multiple like path_00 and so on cause I am doing a test. I just need to know if there is a way to add I believe maybe an element into the matrix I'll be naming
Given what John said, you should rename 'path' to something else, like 'pathij'. Then at the beginning of the code set
pathij = [];
and at the location of your red line you can use:
pathij = [pathij; i j];
If you can anticipate how many values of i,j there will be (let's say N), then it is more efficient to give the array pathij an explicit size, with:
pathij = zeros(N,2);
n = 1;
Then, at the red line you would use:
pathij(n,:) = [i j];
n = n+1;
Khalid Sherif
Khalid Sherif 2020년 12월 25일
Thank you William, that worked.

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

답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

2020년 12월 24일

댓글:

2020년 12월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by