how define input data type
조회 수: 13 (최근 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!