How to search functions for mat use

조회 수: 10 (최근 30일)
hbcukid
hbcukid 2021년 2월 11일
댓글: hbcukid 2021년 2월 12일
I am working in a somewhat large folder and am trying to find out which all files or functions call/use this "test.mat" file. Is there a command I can use to see where all it is used? I tried things like
which who(test.mat)
and
which test.mat -all
but the results only yielded the path
  댓글 수: 2
Rik
Rik 2021년 2월 11일
For m-files you can use a builtin tool (the dependency analyzer) to find which function is a parent function. This has the further limitation that it only works on file in the current folder.
You could use a tool like Notepad++ to search all m files for 'test.mat', but that might not even be enough, as load will also accept the filename without .mat, and functions could do something like S=load(dir('te*.mat').name).
hbcukid
hbcukid 2021년 2월 12일
Searching on Notepad worked, thanks

댓글을 달려면 로그인하십시오.

채택된 답변

John D'Errico
John D'Errico 2021년 2월 11일
편집: John D'Errico 2021년 2월 11일
You can use my mgrep function, downloadable form the file exchange.
In your case, if you want to search for use of that file in your code,
mgrep test.mat . recurse off
The above command will cause mgrep to search for the string 'test.mat'. EVERY file in the current directory will be searched. The directory it will look in is the "dot" directory, that is, the current directory. If you wanted to specify some other directory, then just specify the complete directory path instead of the . in that command.
Finally, the nature of mgrep is by default to then search iteratively down all subdirectories below the one shosen. If you want it to search ONLY the current directory, you would do as I did, set recurse to off.
The default behavior of mgrep is to also show the line where that string occurs. You can turn that off. You can also set a case preference.
For example, I just used this tool, to search in the complete directory of files I've ever written, searching for occurences of the string 'usage'. Here are a few of the hundreds of cases where it found that string.
>> mgrep usage . recurse off
/Users/johnderrico1/Desktop/My_FEX/tessquad.m
% usage 1: res = tessquad(fun,order,data)
% usage 2: res = tessquad(fun,order,data,tess)
% example usage 1: integrate the function x1*x2, over the unit
% example usage 2: integrate the function x1*x2*x3, over the
/Users/johnderrico1/Desktop/My_FEX/triramp.m
% usage: tritarget = triramp(c,space,npixels,background)
/Users/johnderrico1/Desktop/My_FEX/uniqueperms.m
% usage: pu = uniqueperms(vec)
As you can see, it shows which file the call occurs in, as well as the line where it found that string.
You can download mgrep here:

추가 답변 (1개)

Image Analyst
Image Analyst 2021년 2월 12일
I'd type control-shift-F then tell it to search all m-files in some folder and subfolder for whatever you think it might look like, for examples, search for
test.m
test(
test
'test
or however else you might think "test" would appear in your code.

카테고리

Help CenterFile Exchange에서 Search Path에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by