Calling a function without an Output argument
11 次查看(过去 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)
0 个评论
采纳的回答
更多回答(1 个)
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!