call function name in the same function
古いコメントを表示
In a function, I need to run this function somewhere within the function like
function fun
i=1
if i>1
function name
end
end
"function name" is just to call "fun", but I need to create a few copy m files of the above scripts with respective changes in the code so that the function name is actually "copy fun" or "copy 2 fun" etc and I wish "function name" to call "copy fun" or "copy 2 fun" etc.
6 件のコメント
Steven Lord
2024 年 4 月 20 日
Your description is quite vague. Can you post something that's a little closer to pseudocode explaining what you're trying to do?
I suspect what you're actually going to want to do is to write a function that accepts as one of its arguments "which copy" you want to run and performs the appropriate operation based on that input argument rather than making copies of the same function with minor changes. If you do use "copy and paste programming", make absolutely certain you've detected any bugs and locked down what exactly you want your function to do before making copies. Otherwise it's too easy to make changes to N-1 out of the N copies and be confused why your code doesn't do what you think it should.
"but I need to create a few copy m files of the above scripts with respective changes in the code so that the function name is actually "copy fun" or "copy 2 fun" etc and I wish "function name" to call "copy fun" or "copy 2 fun" etc."
This copy-and-pasting code has a very strong https://en.wikipedia.org/wiki/Code_smell
Bruno Luong
2024 年 4 月 20 日
編集済み: Bruno Luong
2024 年 4 月 20 日
@Walter Roberson did you add an "end" to the code posted the original post?
Walter Roberson
2024 年 4 月 20 日
I'm not sure? One might have been added automatically when I formatted the code ?
feynman feynman
2024 年 4 月 21 日
Bruno Luong
2024 年 4 月 21 日
The "end" added by code formatting changes completely the question; whic is not doesn(t make a sense to me.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!