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일

댓글:

2022년 12월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by