Matlab type mismatch in Embedded Matlab Functions

1 回表示 (過去 30 日間)
Owen
Owen 2012 年 11 月 26 日
Hello,
I want to do a CRC-32 for a vector in an Embedded Matlab Function. Before it I've tried it in the Matlab command line and it works. The commands in Matlab look like this:
a = [1;2;3;4;5;6] % a vector
b = dec2bin(a, 8) % converted to binary value
c = b
d = reshape(c, 48, 1) % converted to column vectors
e = double(d) % type conversion
f = e 48 % from ASCII to real values
hGen = comm.CRCGenerator([32 26 23 16 12 11 10 8 7 5 4 2 1 0], 'CheckSumsPerFrame', 1); % polynomial for CRC-32
codeword = step(hGen, f) % CRC-32 generation
but even the first step fails in the Embedded Matlab Function:
"y = dec2bin(a, 8)".
The error: Function output 'y' cannot be of MATLAB type.
What is Matlab type? Can anyone help me to solve this problem?
Thanks Senmeis

回答 (3 件)

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 11 月 26 日
編集済み: Azzi Abdelmalek 2012 年 11 月 26 日
Embedded Matlab function don't allow dec2bin function. You must fix the first problem then look after the second. Maybe the second error is du to the first one.

Kaustubha Govind
Kaustubha Govind 2012 年 11 月 26 日
Please see Alexander's answer on this previously answered question.

Fred Smith
Fred Smith 2012 年 11 月 26 日
Going through a string to get the bitstream is questionable. This is the best alternative I could come up with:
function y = int2bit(u)
% For code generation, input u must be of an integer class.
y = zeros(1,numel(u) * 8);
for i = 1:numel(u)
y(i + (0:7)) = bitget(u(i),1:8);
end
I think this is very close in spirit to what you are trying to do.
HTH,
Fred

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by