在Matlab中将冒号作为函数的参数传递 [英] passing a colon as argument of a function in matlab
问题描述
我想知道是否可以使用冒号:" 作为函数的参数.
I would like to know if it's possible to use a colon ":" as argument of a function.
类似的东西:
function y=func(x)
if x is a colon
do this
else
do that
end
还可以将关键作品 end 作为函数的参数传递,也可以将 1:end , 3:end-5 传递给函数>,等等. 我怀疑是否有可能,但我想确定.
Also is it possible to pass the key work end as argument of a function, and also 1:end, 3:end-5, etc... I doubt it's possible, but I would like to be sure.
此外,当我将"1:end"作为函数的参数传递时,我也会收到一个奇怪的错误,它不会产生任何错误,但是在函数内部,没有分配任何参数(甚至没有其他参数).有人知道会发生什么吗?
Also, I get a weird error when I pass "1:end" as argument of a function, it produces no error, but inside the function, no argument is assigned (not even the other arguments). Do someone know what happens?
推荐答案
您可以为自己的类覆盖这两者:
You can override both for your own classes:
classdef MyClass
properties(Access=public)
data
end
methods
function out = end(A,k,n)
disp(A);
disp(k);
disp(n);
out = [];
end
function B = subsref(A,S)
disp(S);
B = [];
end
end
end
关于功能,我从未听说过这种功能.
As for functions, I never heard of such a functionality.
这篇关于在Matlab中将冒号作为函数的参数传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!