Is There a Way to Find all Shadowed Functions on the matlabpath?

11 visualizaciones (últimos 30 días)
I'm dealing with a code base of m-files all in one folder and sub-folders. I'm worried that different sub-folders contain files with the same name. If I put all of this on my matlabpath, is there any way to get a list of all shadowed functions, i.e., same-named function m-files in different subfolders? Or do I have to use a dir command and do some sort of count of each file name? Or some other way?

Respuesta aceptada

Fangjun Jiang
Fangjun Jiang el 29 de Jun. de 2021
Editada: Fangjun Jiang el 29 de Jun. de 2021
I am not aware of any direct method. On the other hand, Files=dir('**/*.m') will give you all the M-file names including all sub-folders. Then it would be easy to run unique({Files.name}) to find out duplicated file names.
  2 comentarios
Paul
Paul el 29 de Jun. de 2021
I'm not sure how unique() helps. For example suppose I have run that dir() command and put all the filenames into one string vector:
str = ["abc";"defg";"defg";"hij";"klmn";"klmn"];
What I want is something like this:
for ii = 1:numel(str)
counts(ii) = sum(str(ii)==str);
end
str(counts>1)
ans = 4×1 string array
"defg" "defg" "klmn" "klmn"
Actually, I guess that code isn't too bad, but I was hoping for something a little cleaner.
Fangjun Jiang
Fangjun Jiang el 29 de Jun. de 2021
Here is a way to find out duplicated names using unique()
str = ["abc";"defg";"defg";"hij";"klmn";"klmn"];
[UniqStr,IA]=unique(str);
index=setdiff(1:length(str),IA);
DuplicatedStr=str(index)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by