MATLAB NOOB - How to run a downloaded FILE EXCHANGE code - CRC32

5 ビュー (過去 30 日間)
WARRIOR24
WARRIOR24 2020 年 12 月 13 日
コメント済み: Ameer Hamza 2020 年 12 月 14 日
I am relativitly new to MATLAB. Most of my new learnings have been learning how to write and run BASIC Functions. I downloaded this CRC32 bit function from File Exchange and I am having a hard time to run/callout the function.
I am trying to enter a HEX number and return the CRC Calculation in HEX.
function crc = crc32(data)
%crc32 Computes the CRC-32 checksum value of a byte vector.
%--------------------------------------------------------------------------
% CRC = crc32(DATA) computes the CRC-32 checksum value of the data stored
% in vector DATA. The elements of DATA are interpreted as unsigned bytes
% (uint8). The result is an unsigned 32-bit integer (uint32). Polynomial
% bit positions have been reversed, and the algorithm modified, in order
% to improve performance.
% Version: 1.00
% Programmer: Costas Vlachos
% Date: 23-Dec-2014
% Initialize variables
crc = uint32(hex2dec('FFFFFFFF'));
poly = uint32(hex2dec('EDB88320'));
data = uint8(data);
% Compute CRC-32 value
for i = 1:length(data)
crc = bitxor(crc,uint32(data(i)));
for j = 1:8
mask = bitcmp(bitand(crc,uint32(1)));
if mask == intmax('uint32'), mask = 0; else mask = mask+1; end
crc = bitxor(bitshift(crc,-1),bitand(poly,mask));
end
end
crc = bitcmp(crc);

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 12 月 13 日
You can only call a function if placed in the "Current Folder" or placed somewhere on the MATLAB path. You need to download this file, place it in the folder you want and then add that folder to MATLAB's path as described here: https://www.mathworks.com/help/matlab/matlab_env/add-remove-or-reorder-folders-on-the-search-path.html
  2 件のコメント
WARRIOR24
WARRIOR24 2020 年 12 月 14 日
編集済み: WARRIOR24 2020 年 12 月 14 日
I do have it added to to same folder and the right path. When I run it, this is what the command window returns.
>> crc32
Not enough input arguments.
Error in crc32 (line 16)
data = uint8(data);
Ameer Hamza
Ameer Hamza 2020 年 12 月 14 日
You need to call the function with an input argument. Instead of pressing the green run button, run the following in the command window
data = [1 10 2 4]; % example vector
crc32(data)

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by