Calling a function without an Output argument

14 次查看(过去 30 天)
Hi Programmers,
I have a function that plots the phase and magnitude of my signal.
I want this function to plot only the magnitude if no ouput argument is provided when the function is called.
Y = Myplot (a,b)
Y = figure(1)
subplot(2,1,1)
stem (a)
subplot(2,1,2)
stem (b)
% I want to plot only stem (a) when the function is called without the
% output argument.
Myplot (a,b)
stem (a)

采纳的回答

Adam Danz
Adam Danz 2021-4-5
编辑:Adam Danz 2021-4-5
Use nargout to determine the number of output arguments.
if nargout==0
% do something
elseif nargout < 2
% do something else
end
  4 个评论
Telema Harry
Telema Harry 2021-4-5
I modified the code slightly and it gave me the intended result.
if nargout==0
% do something
elseif nargout > 0
% do something else
end
Thank you for your help.

请先登录,再进行评论。

更多回答(1 个)

David Hill
David Hill 2021-4-5
Change the number of input arguments instead
function y=Myplot(varagin)
y=figure;
if nargin==2
subplot(2,1,1);
stem(varagin{1});
subplot(2,1,2);
stem(varagin{2});
else
stem(varagin{1});
end

类别

Help CenterFile Exchange 中查找有关 Multirate Signal Processing 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by