how define input data type
14 次查看(过去 30 天)
显示 更早的评论
when defining a function, for example
function y = func(x)
how can I define that x is of a specific type, like uint8?
0 个评论
采纳的回答
更多回答(2 个)
Jan
2011-3-31
I do not see the problem.
function y = func(x)
disp(x + x)
And then call it with an UINT8:
func(uint8(1:10))
Or do you want to reject inputs with a deviating type? Then:
function y = func(x)
if ~isa(x, 'uint8')
error('Bad type!');
end
disp(x + x)
Or do you want to convert the input?
function y = func(x)
x = uint8(x);
disp(x + x)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 MATLAB Code Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!