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!