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 Comment

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.

Sign in to comment.

Answers (0)

Categories

Products

Release

R2021a

Asked:

on 11 Dec 2022

Commented:

on 12 Dec 2022

Community Treasure Hunt

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

Start Hunting!