Matlab Function on simulink does not read array

I have this function on a triggered subsystem:
function [arrayData,prevData] = movingAvgSpeed(prevDataArray)
%Initialize array
arrayData = zeros(16,2);
%Fill it with data
arrayData(1,1) = currentSpeed; %This is lets say 100.
%Test to check if prevDataArray input has anything inside.
prevData = prevDataArray(1,1); %This outputs zero
--------------------------------------------------------------------------------------------------------------------
I have connected arrayData to prevDataArray through a memory block (I have also tried a unit delay block). I have both with (zeros(16,2)) as initial condition. I have tested, and the array before and after the memory block outputs the correct data, but when I try to read it from the function, it just outputs zero. Even if I try to output prevDataArray on a new output port, it outputs zero. It's like the function can't read the array.
I have checked with simulink signal size and it shows the correct 16x2 array.
I'm using Matlab 2021.
I'm out of ideas, I'd appreciate some advice.
EDIT1: I see now that in order to use all the data you input on an array, you have to use num2cell on matlab functions. Is there an equivalent for simulink?

1 个评论

Best way is for you to attach a simple model. Get rid of the triggered subsystem. Make the size as 3x2 to figure out the problem.

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Event Functions 的更多信息

产品

版本

R2021a

提问:

2022-12-11

Community Treasure Hunt

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

Start Hunting!

Translated by