# Guy and Seth on Simulink

## Sum Block: Round or Rectangular?

Working in technical support, I see a lot of Simulink models from users. I have realized that many users do not know how to, or do not take the time to configure the ports of the Sum block.

For example, when I see things like this, it makes my eyes hurt a little:

Here are a few tips to format the Sum block to make your models easier to understand.

Round Sum block

When you drag the Sum block from the Simulink Library Browser, its Icon Shape is set to Round, and it has one input port on the left and one on the bottom:

When the Sum block Icon Shape is set to Round, the ports are spread evenly from top to bottom and the vertical bar "|" can be used to skip one position. For example, if we want to add a port on top of the block, we can modify the list of signs:

Rectangular Sum block

If you change the Icon Shape property of the default Sum block to Rectangular, the block will look like the following:

Personally, I can not think of a good reason for skipping a port in Rectangular shape. So I almost always remove the "|" when I change the shape to Rectangular.

Sum of Elements

One way I like to use the Sum block is to sum all the elements of a vector or matrix:

For matrices, the Sum block can also be configured to Sum only over one specific dimension:

Round or Rectangular?

One question remains: When should the Sum block be Round and when should it be Rectangular?

There is no absolute rule, but personally I like to use the Rectangular shape when implementing equations that flow from left to right, without obvious feedback. For example:

I keep the Round shape for when I want to make it obvious that there is a feedback involved:

Please share with us if you have rules or guidelines on the format of your blocks by leaving a comment here.

### 5 Responses to “Sum Block: Round or Rectangular?”

1. Paul replied on :

Yes it’s pretty silly to still be including two separate blocks in the library when there is no functional difference between them. It can even be confusing to new users. Back in the day, I used to think the round block should be used for continuous applications and the square block for discrete. Really, they should be combines, and the visual preference relegated to being a simple mask parameter…

2. Ryan replied on :

Great post. Whenever I receive a model with a square sum for a control system I have to change them over to circular. Nothing technically wrong, but I like the relationship between circular summing junctions and control system diagrams.

3. Guy Rouleau replied on :

@Paul, Having multiple instances of the same block with different settings is something relatively common in the Simulink Library Browser. For many users, it seems to make it easier to find what they are looking for.

For example:

- The Math section of the library contains 4 instances of the Sum block: Sum, Add, Subtract and Sum of Elements. It also contains 3 instances of the Product block: Product, Divide and Product of Elements

- Resettable Delay and Variable Integer Delay are both instances of the generic Delay block.

- Lookup Tables blocks: 1-D, 2-D and N-D are the same block with different settings.

- Vector Concatenate and Matrix Concatenate

4. Paul replied on :

@Guy
These duplicate blocks should be removed in a future release IMHO.
It’s just not good practice to have different blocks doing the same thing when the variations could be achieved with mask settings.
If you are concerned with people still looking for the old blocks, there are many solutions to this. For example, I often use the search field to say find an “add block”. You could update the search terms so that “sum” also gives the “add” block result.
Other more complex solutions exist, such as retaining the original blocks, but having them immediately convert to the “add” block on placement in the model…
Ultimately, I there should not be multiple blocks for the same function. And any time you are using historical convention to justify something concerns me! It means you are being held back in progress…

5. Issopui replied on :

Hello guys,

I’m very sorry for my comment which may not be related to the topic but it is related to simulink blockset.

I am working on a small project using computer vision sytem toolbox. I have 3 images which I need to convert to grayscale and then subtract image2 from image one do the binary thresholding and finanlly the AND logic gate to find the final position.

My question is “Which blockset should I use to subtract two grayscale images?” I have tried the subtract blockset from math operation but my output image look exactly like the one I got after thresholding.

Please guys help me being trying for weeks now. What is the proper blockset to be used for two grayscale subtraction?

I’m sorry for my long message. Wish u guys will me

Issopui

 Name (required) E-mail (required, will not be published) Website (optional) Spam protection (required): What is 5 + 10 ?

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>


If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).

Guy Rouleau and Seth Popinchalk are Application Engineers for MathWorks. They write here about Simulink and other MathWorks tools used in Model-Based Design.

These postings are the author's and don't necessarily represent the opinions of MathWorks.