我想要绘制序列,我写了一个函数如何在Matlab中重载用户定义的函数?
function show_seq(seq)
plot (seq)
end
我现在想重载此show_seq显示2个序列类似
function show_seq(seq1, seq2)
plot(seq1,'color','r');
plot(seq2, 'color', 'b');
end
但这不工作,没有任何人有有关如何在MATLAB中重载函数的想法?
我想要绘制序列,我写了一个函数如何在Matlab中重载用户定义的函数?
function show_seq(seq)
plot (seq)
end
我现在想重载此show_seq显示2个序列类似
function show_seq(seq1, seq2)
plot(seq1,'color','r');
plot(seq2, 'color', 'b');
end
但这不工作,没有任何人有有关如何在MATLAB中重载函数的想法?
如果将重载函数放在优先级较高的路径中,则可以重载自己的某个函数。有关路径优先级的更多详细信息,请参阅this question。
然而,在你的情况下,最简单的是修改show_seq
,使其接受多个可选输入:
function show_seq(varargin)
hold on %# make sure subsequent plots don't overwrite the figure
colors = 'rb'; %# define more colors here,
%# or use distingushable_colors from the
%# file exchange, if you want to plot more than two
%# loop through the inputs and plot
for iArg = 1:nargin
plot(varargin{iArg},'color',colors(iArg));
end
end
相关:http://stackoverflow.com/questions/8630889/overloading-functions/8631335 #8631335 –