a function that has two inputs: a number and a row vector
2 次查看(过去 30 天)
显示 更早的评论
The code i am tryin to make requires that there be only two inputs, the first a number and the second as a row vector. How do I do that? I have tried looking online and even in my textbook but i cant find anything.
I should calarify, when calling the function the command window should read My_func(1,[18 11 22 48]).
What I have in my .m file is function y = My_func(a,b,c,d,e), I believe this is where I am having a lack of knowlege.
2 个评论
Torsten
2022-4-9
function y = My_func(a,bcde)
b = bcde(1);
c = bcde(2);
d = bcde(3);
e = bcde(4);
end
回答(2 个)
KSSV
2022-4-9
function val = myfun(a,b)
if numel(a) ~= 1 | size(b,1) ~=1
error('check the inputs') ;
end
% Do what you want
end
1 个评论
Steven Lord
2022-4-9
Instead of using numel and size here, I recommend using isscalar and isrow or isvector (depending on whether you care about the orientation or just whether or not the input is a vector.)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!