1

I have been trying to multiply 2 sets of timeseries data in Simulink, At and Bt, and I expected the result to be like this:

ans = sum(A(1:t)*B(t:-1:1))

For instance, when t = 3, the result should be

ans =At1*Bt1 + (At2*Bt1 + At1*Bt2) + (At3*Bt1 + At2*Bt2 + At3*Bt1)

I got these 2 datasets from one of my Simulink models and I want to continue my simulation with the same model.

To achieve this, I guess I need to flip one of those 2 datasets. So I tried the Matlab function flip(), but it doesn't work when the argument is a timeseries.

Then I tried to first output those data to Matlab workspace as arrays and flipped them, and then input them back to my Simulink model, but this didn't work as well because in those arrays there are no any columns storing Time information.

At last, I found that there is a block called "Flip" in the DSP Toolbox, but the thing is that I don't have this toolbox, probably we won't buy it, and I am not sure if this block works.

CJW
  • 11
  • 2

1 Answers1

0

If that is what you need, then write a function to do that:

function C = multiply_timeseries(A, B)

Alen = length(A.Data);
Blen = length(B.Data);

if ~(Alen == Blen)
    error("A and B length should be the same")
end

C = timeseries(zeros(1,Alen,'like',A.Data), A.Time);

for t = 1:Alen
    C.Data(t) = sum( A(1:t) * B(t:-1:1) );
end

end

Modify the above to suit your needs.

Amin Ya
  • 1,515
  • 1
  • 19
  • 30
  • Thank you for your answer. This code worked in Matlab but didn't work in Simulink, saying "Simulink does not have enough information to determine output sizes for this block." and "Simulink cannot determine sizes and/or types of the outputs for this block due to errors in the block body, or limitations of the underlying analysis." Maybe I didn't make it clear that I got these 2 datasets from my Simulink model and I want to continue my simulation with the same model. Probably I should create one more Simulink model that starts from the multiplied result of these 2 datasets? – CJW Mar 12 '20 at 08:06
  • Simulink's compiler isn't doing a good job here. You can specify the size of inputs and outputs manually by opening your Matlab function > editor tab > edit data button. – Amin Ya Mar 12 '20 at 18:42