Simulink Mathlab Function Block Output Variable Size Array
3 次查看(过去 30 天)
显示 更早的评论
Hi,
I encountered the problem about array size from matlab function block. First of all I was creating a simulink project about data control. Its include some input values (constant blocks), mathlab function and display block. The input data is the address value, the length of the data to be transmitted and other values. Also, all the value type is uint8. Matlab function block is doing generate new array for output data. This array length is variable (regValue). For example lets assume the regValue is a 3. newArray length is a equal to that. In that case newArray = [data1 data2 data3]. But this program getting failure about variable type. At the same time, pins y5 and y6 are connected to the display block. How can I do this?
Some Errors;


Block Diagram:

Code:
function [y1, y2, y3, y4, y5] = response(slaveAddr, funcCode, startAddr, regValue)
%#codegen
% slaveAddr: 1 byte (Slave adresi)
% funcCode: 1 byte (Fonksiyon kodu)
% startAddr: 2 byte (Başlangıç adresi)
% regValue: 2 byte (Register değeri veya değerleri)
% crc1, crc2: 1 byte (Her iki CRC byte'ı)
% generalData: (23 byte veri)
% Verileri başlatıyoruz
y1 = uint8(slaveAddr); % 1 byte slave address
y2 = uint8(funcCode); % 1 byte function code
y3 = uint8(regValue * 2); % 1 byte Byte Count
totalValue = (y3+2); % Başlangıçta boş veri High
y4 = zeros(1, totalValue);
y5 = zeros(1, length(y3));
end
0 个评论
回答(1 个)
Walter Roberson
2024-12-25
Insert
totalValue = uint8(0);
before
totalValue = (y3+2);
4 个评论
Walter Roberson
2024-12-25
y3 = uint8(regValue * 2); % 1 byte Byte Count
totalValue = (y3+2); % Başlangıçta boş veri High
y4 = zeros(1, totalValue);
y3 is a uint8, so the maximum value it can hold is 255.
Adding 2 to a uint8 with value 255, gets 255 again. So the maximum value of totalValue is 255.
It follows that y4 is somewhere between 2 elements and 255 elements.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!