cuốn sách gpt4 ai đã làm

MATLAB - Có một số quy trình Matlab nhất định được sử dụng trong các tập lệnh Matlab không?

In lại Tác giả: Vũ trụ không gian 更新时间:2023-11-03 19:34:01 27 4
mua khóa gpt4 Nike

我正在运行一个不是我自己编写的大 m 文件,它依赖于某些子函数。我想知道是否在所有嵌套函数的任何地方都使用了特定函数(在我的例子中是函数 eig.m(计算特征值))。有没有快速的方法来做到这一点?

亲切的问候,公园

câu trả lời hay nhất

Bạn có thể sử dụng半文档化chức nănggetcallinfo(有关它的更多信息,请参阅Yair Altman's blog):

getcallinfo

Trả lại called functions and their first and last lines
This function is unsupported and might change or be removed without notice in a future version.

一般使用getcallinfo

让我们创建一个示例脚本, trong đó có chứa子函数(这适用于in Matlab R2016b 或更新版本)并将其保存为'filename.m' .如果存在嵌套函数,或者如果主文件是chức năng而不是脚本,该过程也适用。

x = input('');
y = find(x);
z = f(norm(x));
disp(z)
function u = f(v)
u = -log2(v) + log2(pi);
end

Sau đó:

>> g = getcallinfo('filename.m');

为您提供一个包含有趣信息(包括函数调用)的嵌套结构数组。第一个条目 g(1) 指的是主文件。子功能或嵌套功能可能还有更多条目。在这种情况下,g(2) 指的是子函数 f.

>> g(1).calls.fcnCalls
trả lời =
struct with fields:
names: {'input' 'find' 'norm' 'disp' 'log2' 'log2' 'pi'}
lines: [1 2 3 4 6 6 6]

>> g(1).calls.innerCalls
trả lời =
struct with fields:
names: {'f'}
lines: 3

>> g(2).calls.fcnCalls
trả lời =
struct with fields:
names: {'log2' 'log2' 'pi'}
lines: [6 6 6]

>> g(2).calls.innerCalls
trả lời =
struct with fields:
names: {1×0 cell}
lines: [1×0 double]

g 的其他字段提供更多详细信息,例如姓名

>> g(1).name
trả lời =
filename

>> g(2).name
trả lời =
f

或输入

>> g(1).type
trả lời =
Script with no properties.

>> g(2).type
trả lời =
subfunction

如何确定给定函数是否在文件中的任何地方使用

按照上面的解释获取g, và sau đó trongg的所有calls.fcnCalls.names字段中寻找想要的函数名:

g = getcallinfo('filename.m');
sought_function = 'log2'; % or 'eig' in your case
t = arrayfun(@(x) x.calls.fcnCalls.names, g, 'UniformOutput', false);
% collect all names of called functions. Gives a cell array of cell arrays
% of strings (character vectors)
t = [t{:}]; % de-nest: concatenate into cell array of strings
result = any(strcmp(t, sought_function)); % compare with sought function name

关于matlab - matlab 脚本中是否使用了某些 matlab 例程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46358432/

27 4 0
không gian vũ trụ
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress