call function name in the same function
Afficher commentaires plus anciens
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 commentaires
Steven Lord
le 20 Avr 2024
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
le 20 Avr 2024
Modifié(e) : Bruno Luong
le 20 Avr 2024
@Walter Roberson did you add an "end" to the code posted the original post?
Walter Roberson
le 20 Avr 2024
I'm not sure? One might have been added automatically when I formatted the code ?
feynman feynman
le 21 Avr 2024
Bruno Luong
le 21 Avr 2024
The "end" added by code formatting changes completely the question; whic is not doesn(t make a sense to me.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!