How to change the function name to match its file name in a code?
Mostrar comentarios más antiguos
Hello,
I have a simple question, I think!
If we have a function named hello.m but its file name is called Hi then how to change the function
name to Hi.m (to make it match the file name) NON-manually?
Imagine you need to do this for 565676577 number of files in a for-loop.
Do you know a way? it is greatly appreciated.
Babak
8 comentarios
Jiri Hajek
el 5 de Dic. de 2022
Editada: Jiri Hajek
el 5 de Dic. de 2022
Hi, since all m files are just text files, you can use file editing functions to analyse the header, identify function name and rewrite as required. It will require some coding and testing, but it's not very difficult either.
Cris LaPierre
el 5 de Dic. de 2022
Pehaps you can help us by sharing how the 565676577 function files were created in the first place?
565'676'577 files?! Seriously? The movefile command needs about 0.01 seconds per file when writing on a SSD. Then renaming your files takes about 64 days of processing time. But you want to change the contents of the files and rewrite them. So expect the code to run several 100 days.
"hello.m" and "Hi.m" are no valid function names. Do you mean a file called "Hi.m", which contains the function "hello", which should be renamed to "Hi"?
This renaming of the function is not trivial. The identification of the function name has to consider some exceptions:
% A comment
%{
A block comment
function notTheFunctionName
%}
function thisIsTheName
Or:
classdef thisIsMyClass
...
end
Scripts must be excluded also.
Please explain the unclear parts of the question.
Mohammad Shojaei Arani
el 5 de Dic. de 2022
Stephan
el 5 de Dic. de 2022
"...PLEASE DO NOT TELL ME ANYTHING OTHER THAN THE SOLUTION. Simply show me how you code this. If you do not like to do this then simply skip this and I am fine with it."
Maybe you should consider to pay somebody to this task for you - then you will get what you want
Mohammad Shojaei Arani
el 5 de Dic. de 2022
@Mohammad Shojaei Arani: Please consider the Community Guidelines. SHOUTING and disrespectful communication is not welcome here.
It is useful, if you answer questions for clarifications. I have mentioned the problems of an automatic renaming already and you did not react yet. You did not clarify the problem of the confused function name "hello.m" and file name "Hi". It wastes the time of the readers, if you mention 565'676'577 files, although you have 1000 files only.
It motivates readers to assist you, if you show, what you have tried so far.
Mohammad Shojaei Arani
el 6 de Dic. de 2022
Respuestas (0)
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!