how define input data type

14 ビュー (過去 30 日間)
Vasiliki
Vasiliki 2011 年 3 月 31 日
when defining a function, for example
function y = func(x)
how can I define that x is of a specific type, like uint8?

採用された回答

David Young
David Young 2011 年 3 月 31 日
See
doc validateattributes

その他の回答 (2 件)

Jan
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)

Vasiliki
Vasiliki 2011 年 3 月 31 日
I want to generate c code using the embedded toolbox. The default type of the input is double, but I need integers or fixed point in order to use the c code in a microprocesor. So, I want to see if there is a way that matlab can "understand" that the input will be integer so that when it generates the c code i will have:
uint16 func (uint16 u)
Of course after the generation of the code I can do it maually, but I want to see if there is an automatic way.
  1 件のコメント
Vasiliki
Vasiliki 2011 年 4 月 6 日
it can be done at the compilation with emlc and -eg emlcoder.egs, defining that the input is of variable size and its type and class is the desirable one.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB Code Analysis についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by