Simulink Mathlab Function Block Output Variable Size Array
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Walter Roberson
el 25 de Dic. de 2024
Insert
totalValue = uint8(0);
before
totalValue = (y3+2);
4 comentarios
Walter Roberson
el 25 de Dic. de 2024
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.
Ver también
Categorías
Más información sobre Sources en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!