MATLAB Answers

0

How to do array operation With simulink blocks ?

I was designed below code with State flow. But I unable to do with the Simulink blocks.
please let me know, how to with the Simulink.
uint8 sampleFunction(uint8 *A, uint8 *B)
{
for(i=0;i<n;i++)
{
Temp = 0;
if(A[i] == B[i])
{
Temp = A[i] + B[i];
}
}
return Temp;
}
  • > How we can take dynamic array ?

  0 Comments

Sign in to comment.

2 Answers

Answer by Sasidhar Duggireddy on 12 Jun 2019
 Accepted Answer

Please find the below example for more idea about for loop.
I hope this example can help
Capture.JPG

  0 Comments

Sign in to comment.


Answer by Nick Sarnie on 5 Jun 2019
Edited by Nick Sarnie on 5 Jun 2019

Hi Sasidhar,
It looks like that loop is adding two matricies. The "Add" or "Sum" block can do this:
If the matrix size is constant once the simulation has started, you can simply set the dimensions in the block parameters. To make it easier, consider using Simulink.Parameters for the dimensions instead.
If the matrix size will change between simulation steps, you can use variable size signals.
Thanks,
Nick

  2 Comments

Hello Nick
I know how do addition of two scalars(numbers) with add operator. I want know how to add the array elements with one constant or array of elements.
Thanks for your reply.
Hi Sasidhar,
Can you provide an example of this operation?
Thanks,
Nick

Sign in to comment.