How do I check if there is a function with the same name (2024)

37visualizaciones (últimos 30días)

Mostrar comentarios más antiguos

中祥 范 el 4 de Jun. de 2024 a las 14:23

  • Enlazar

    Enlace directo a esta pregunta

    https://la.mathworks.com/matlabcentral/answers/2125381-how-do-i-check-if-there-is-a-function-with-the-same-name

  • Enlazar

    Enlace directo a esta pregunta

    https://la.mathworks.com/matlabcentral/answers/2125381-how-do-i-check-if-there-is-a-function-with-the-same-name

Respondida: Voss el 4 de Jun. de 2024 a las 15:34

In addition to the functions that come with matlab, I have added some additional toolboxes, so I want to make sure that there are more than one function with the same name in my directory, who can teach me.

0 comentarios

Mostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Iniciar sesión para responder a esta pregunta.

Respuestas (2)

Star Strider el 4 de Jun. de 2024 a las 14:28

  • Enlazar

    Enlace directo a esta respuesta

    https://la.mathworks.com/matlabcentral/answers/2125381-how-do-i-check-if-there-is-a-function-with-the-same-name#answer_1467461

  • Enlazar

    Enlace directo a esta respuesta

    https://la.mathworks.com/matlabcentral/answers/2125381-how-do-i-check-if-there-is-a-function-with-the-same-name#answer_1467461

Abrir en MATLAB Online

The which function can be helpful.

which which -all

built-in (/MATLAB/toolbox/matlab/general/which)

If there are any others in your MATLAB search path, it should display them as well.

.

4 comentarios

John D'Errico el 4 de Jun. de 2024 a las 14:31

Enlace directo a este comentario

https://la.mathworks.com/matlabcentral/answers/2125381-how-do-i-check-if-there-is-a-function-with-the-same-name#comment_3179216

  • Enlazar

    Enlace directo a este comentario

    https://la.mathworks.com/matlabcentral/answers/2125381-how-do-i-check-if-there-is-a-function-with-the-same-name#comment_3179216

Editada: John D'Errico el 4 de Jun. de 2024 a las 14:32

Which is the first choice of course, but exist is another option.

Star Strider el 4 de Jun. de 2024 a las 14:36

Enlace directo a este comentario

https://la.mathworks.com/matlabcentral/answers/2125381-how-do-i-check-if-there-is-a-function-with-the-same-name#comment_3179221

  • Enlazar

    Enlace directo a este comentario

    https://la.mathworks.com/matlabcentral/answers/2125381-how-do-i-check-if-there-is-a-function-with-the-same-name#comment_3179221

@John D'Errico — Noted. Thank you.

中祥 范 el 4 de Jun. de 2024 a las 14:53

Enlace directo a este comentario

https://la.mathworks.com/matlabcentral/answers/2125381-how-do-i-check-if-there-is-a-function-with-the-same-name#comment_3179246

  • Enlazar

    Enlace directo a este comentario

    https://la.mathworks.com/matlabcentral/answers/2125381-how-do-i-check-if-there-is-a-function-with-the-same-name#comment_3179246

Thank you for your answer, but what I want to do is check if there are any functions with the same name in my path.

The 'which' function seems to only check one by one.

Star Strider el 4 de Jun. de 2024 a las 15:09

Enlace directo a este comentario

https://la.mathworks.com/matlabcentral/answers/2125381-how-do-i-check-if-there-is-a-function-with-the-same-name#comment_3179276

  • Enlazar

    Enlace directo a este comentario

    https://la.mathworks.com/matlabcentral/answers/2125381-how-do-i-check-if-there-is-a-function-with-the-same-name#comment_3179276

Abrir en MATLAB Online

It will detect all of them with the -all flag.

For example, the extremely useful matrix-left-divide (the \ operator) called mldivide, \

which mldivide -all

built-in (/MATLAB/toolbox/matlab/ops/mldivide)built-in (/MATLAB/toolbox/matlab/ops/@double/mldivide) % double methodbuilt-in (/MATLAB/toolbox/matlab/ops/@int16/mldivide) % int16 methodbuilt-in (/MATLAB/toolbox/matlab/ops/@int32/mldivide) % int32 methodbuilt-in (/MATLAB/toolbox/matlab/ops/@int64/mldivide) % int64 methodbuilt-in (/MATLAB/toolbox/matlab/ops/@int8/mldivide) % int8 methodbuilt-in (/MATLAB/toolbox/matlab/ops/@logical/mldivide) % logical methodbuilt-in (/MATLAB/toolbox/matlab/ops/@single/mldivide) % single methodbuilt-in (/MATLAB/toolbox/matlab/ops/@uint16/mldivide) % uint16 methodbuilt-in (/MATLAB/toolbox/matlab/ops/@uint32/mldivide) % uint32 methodbuilt-in (/MATLAB/toolbox/matlab/ops/@uint64/mldivide) % uint64 methodbuilt-in (/MATLAB/toolbox/matlab/ops/@uint8/mldivide) % uint8 method/MATLAB/toolbox/matlab/datatypes/duration/@duration/mldivide.m % duration method/MATLAB/toolbox/matlab/timeseries/@timeseries/mldivide.m % timeseries methodmldivide is a built-in method % matlab.internal.capability.Capability methodmldivide is a built-in method % connector.internal.LoggerLevel methodmldivide is a built-in method % matlab.lang.OnOffSwitchState method/MATLAB/toolbox/matlab/timeseries/+tsdata/@datametadata/mldivide.m % tsdata.datametadata methodmldivide is a built-in method % matlab.internal.reference.property.RefEntityType methodmldivide is a built-in method % matlab.internal.reference.api.EntityPrecision methodmldivide is a built-in method % matlab.internal.reference.property.DeprecationStatus methodmldivide is a built-in method % matlab.internal.reference.property.FunctionType methodmldivide is a built-in method % matlab.internal.reference.property.SyntaxType methodmldivide is a built-in method % matlab.internal.reference.api.EntityCaseSensitivity methodmldivide is a built-in method % simulink.FindSystemTask.Status methodmldivide is a built-in method % mf.zero.meta.Language methodmldivide is a built-in method % dig.config.CommandType methodmldivide is a built-in method % dig.config.HorizontalAlignment methodmldivide is a built-in method % dig.config.ResourceState methodmldivide is a built-in method % dig.config.ResourceType methodmldivide is a built-in method % dig.model.DisplayState methodmldivide is a built-in method % dig.model.EventDataType methodmldivide is a built-in method % dig.model.FunctionType methodmldivide is a built-in method % dig.model.ValidInBdType methodmldivide is a built-in method % dig.model.ViewMode methodmldivide is a built-in method % matlab.unittest.internal.fixtures.FolderScope methodmldivide is a built-in method % matlab.automation.Verbosity methodmldivide is a built-in method % matlab.internal.timer.CallBackTypeEnum methodmldivide is a built-in method % matlab.internal.timer.BusyModeEnum methodmldivide is a built-in method % matlab.internal.timer.ExecutionModeEnum method/MATLAB/toolbox/matlab/bigdata/@tall/mldivide.m % tall methodbuilt-in % gpuArray method/MATLAB/toolbox/econ/econ/@LagOp/mldivide.m % LagOp method/MATLAB/toolbox/parallel/array/distributed/@distributed/mldivide.m % distributed method/MATLAB/toolbox/parallel/array/distributed/@codistributed/mldivide.m % codistributed method/MATLAB/toolbox/parallel/gpu/gpu/@gpuArray/mldivide.m % gpuArray method/MATLAB/toolbox/shared/controllib/engine/@StaticModel/mldivide.m % StaticModel method/MATLAB/toolbox/shared/controllib/engine/@DynamicSystem/mldivide.m % DynamicSystem method/MATLAB/toolbox/wavelet/wavelet/@laurpoly/mldivide.m % laurpoly method

.

Iniciar sesión para comentar.

Voss el 4 de Jun. de 2024 a las 15:34

  • Enlazar

    Enlace directo a esta respuesta

    https://la.mathworks.com/matlabcentral/answers/2125381-how-do-i-check-if-there-is-a-function-with-the-same-name#answer_1467491

  • Enlazar

    Enlace directo a esta respuesta

    https://la.mathworks.com/matlabcentral/answers/2125381-how-do-i-check-if-there-is-a-function-with-the-same-name#answer_1467491

Abrir en MATLAB Online

You can loop over the m-files in your folder, call which(_,'-all') on each one, and store information about what which returned:

F = dir('*.m');

for ii = 1:numel(F)

C = which(F(ii).name,'-all');

F(ii).instances = C;

F(ii).is_duplicate = numel(C) > 1;

end

Then the files that have same-name duplicates somewhere on the path are

D = F([F.is_duplicate]);

and their same-name duplicate locations are given by

D.instances

Example:

% create some folders with m-files

% Folder1 contains file1.m and file4.m

mkdir('Folder1')

fid = fopen(fullfile('Folder1','file1.m'),'w'); fclose(fid);

fid = fopen(fullfile('Folder1','file4.m'),'w'); fclose(fid);

% Folder2 contains file1.m and file2.m

mkdir('Folder2')

fid = fopen(fullfile('Folder2','file1.m'),'w'); fclose(fid);

fid = fopen(fullfile('Folder2','file2.m'),'w'); fclose(fid);

% add the folders to the path

addpath('Folder1','Folder2')

% the current folder contains file1.m, file2.m, and file3.m

fid = fopen('file1.m','w'); fclose(fid);

fid = fopen('file2.m','w'); fclose(fid);

fid = fopen('file3.m','w'); fclose(fid);

% run the code above

F = dir('*.m');

for ii = 1:numel(F)

C = which(F(ii).name,'-all');

F(ii).instances = C;

F(ii).is_duplicate = numel(C) > 1;

end

% F contains info about the files in the current folder

F

F = 3x1 struct array with fields:

name folder date bytes isdir datenum instances is_duplicate

F.name

ans = 'file1.m'

ans = 'file2.m'

ans = 'file3.m'

% D contains info about those files that have same-name duplicates

% somewhere on the path

D = F([F.is_duplicate])

D = 2x1 struct array with fields:

name folder date bytes isdir datenum instances is_duplicate

D.name

ans = 'file1.m'

ans = 'file2.m'

% D.instances tells you where the duplicates are

D.instances

ans = 3x1 cell array

{'/users/mss.system.v6zxt/file1.m' } {'/users/mss.system.v6zxt/Folder1/file1.m'} {'/users/mss.system.v6zxt/Folder2/file1.m'}

ans = 2x1 cell array

{'/users/mss.system.v6zxt/file2.m' } {'/users/mss.system.v6zxt/Folder2/file2.m'}

0 comentarios

Mostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Iniciar sesión para responder a esta pregunta.

Ver también

Categorías

MATLABGraphicsImages

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

Etiquetas

  • function

Productos

  • MATLAB

Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Se ha producido un error

No se puede completar la acción debido a los cambios realizados en la página. Vuelva a cargar la página para ver el estado actualizado.


Translated by How do I check if there is a function with the same name (8)

How do I check if there is a function with the same name (9)

Seleccione un país/idioma

Seleccione un país/idioma para obtener contenido traducido, si está disponible, y ver eventos y ofertas de productos y servicios locales. Según su ubicación geográfica, recomendamos que seleccione: .

También puede seleccionar uno de estos países/idiomas:

América

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europa

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia-Pacífico

Comuníquese con su oficina local

How do I check if there is a function with the same name (2024)

References

Top Articles
Latest Posts
Article information

Author: Corie Satterfield

Last Updated:

Views: 6253

Rating: 4.1 / 5 (42 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Corie Satterfield

Birthday: 1992-08-19

Address: 850 Benjamin Bridge, Dickinsonchester, CO 68572-0542

Phone: +26813599986666

Job: Sales Manager

Hobby: Table tennis, Soapmaking, Flower arranging, amateur radio, Rock climbing, scrapbook, Horseback riding

Introduction: My name is Corie Satterfield, I am a fancy, perfect, spotless, quaint, fantastic, funny, lucky person who loves writing and wants to share my knowledge and understanding with you.