Info

この質問は閉じられています。 編集または回答するには再度開いてください。

to change without using function in MATLAB

2 ビュー (過去 30 日間)
chan
chan 2015 年 12 月 4 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
here is a program code in C using function and recursion.i dnt know how to convert this code into normal code without using function and recursion in matlab
for(i=1;i<=num_of_vertices;i++)
{
printpath(source,i,predecessor);
if(pathestimate[i]!=999)
printf("->(%d)\n",pathestimate[i]);
}
void printpath(int x,int i,int p[])
{
printf("\n");
if(i==x)
printf("%d",x);
else if(p[i]==0)
printf("Number Path From %d To %d",x,i);
else
{
printpath(x,p[i],p);
printf("..%d",i);
}
}
*PLEASE HELP ME

回答 (1 件)

Guillaume
Guillaume 2015 年 12 月 4 日
Functions are an essential part of programming languages and make the code clearer. Why wouldn't you want to use them in matlab?
Recursion also works in matlab, and in this case, I don't see any problem with using recursion. So once again, why would you not want to use it?
I would just simply use the exact same code structure. It's trivial to rewrite in matlab (just replacing printf by fprintf and [] by () is pretty much all that is required). However, I would add comments to the code and use meaningful variable names, so that whoever reads the code doesn't have to remember what the heck x, i and p are supposed to represent.

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by