repmat function in Simulink (2024)

42 views (last 30 days)

Show older comments

Rubem Pacelli on 16 Aug 2020

  • Link

    Direct link to this question

    https://www.mathworks.com/matlabcentral/answers/580266-repmat-function-in-simulink

  • Link

    Direct link to this question

    https://www.mathworks.com/matlabcentral/answers/580266-repmat-function-in-simulink

Edited: Ivan Garcia on 30 Jul 2021

Accepted Answer: Ivan Garcia

Open in MATLAB Online

I would like to perform the repmat() function in Simulink. Apparently, there isn't a block for this purpose. So I doing this using the MATLAB function block. Here the following signal dimensions that I'm trying to handle

repmat function in Simulink (2)

The code is just:

function y = repmat(u, Ns)

y = repmat(u, [Ns,1,1]); % Ns is a paramater of my system

It works, but using this block is always awkward and inefficient. Is there a clever way to do this?

15 Comments

Show 13 older commentsHide 13 older comments

hosein Javan on 16 Aug 2020

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/580266-repmat-function-in-simulink#comment_974979

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/580266-repmat-function-in-simulink#comment_974979

Edited: hosein Javan on 16 Aug 2020

repmat is usally used for element wise operations. if you can tell why even thinking of repmat, maybe there's a better solution of that.

Walter Roberson on 16 Aug 2020

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/580266-repmat-function-in-simulink#comment_975045

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/580266-repmat-function-in-simulink#comment_975045

from your diagram I would have expected repmat(u, [1,1, Ns]) unless you wanted a different element order and you had hardwired the output size to prevent conflicts on the number of dimensions.

Walter Roberson on 16 Aug 2020

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/580266-repmat-function-in-simulink#comment_975048

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/580266-repmat-function-in-simulink#comment_975048

I do not agree that repmat is used for elementwise operations. That would be repelems

hosein Javan on 16 Aug 2020

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/580266-repmat-function-in-simulink#comment_975060

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/580266-repmat-function-in-simulink#comment_975060

hello Mr. Walter Roberson . for example if we want to multiply each row of a matrix by a vector, that would be repmat(k,[m 1]).*A which is element wise. from my experience, it is a faster way than loops. called vectorization I assume.

Walter Roberson on 16 Aug 2020

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/580266-repmat-function-in-simulink#comment_975075

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/580266-repmat-function-in-simulink#comment_975075

If k is a vector with the same number of columns as matrix A, then all you need since R2016b is k.*A . This is "implicit expansion".

hosein Javan on 16 Aug 2020

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/580266-repmat-function-in-simulink#comment_975093

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/580266-repmat-function-in-simulink#comment_975093

I'm using 2016a, thanks for implying that. I'm just concerned that newer versions aren't too RAM-friendy!

Walter Roberson on 16 Aug 2020

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/580266-repmat-function-in-simulink#comment_975126

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/580266-repmat-function-in-simulink#comment_975126

bsxfun for earlier releases

hosein Javan on 17 Aug 2020

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/580266-repmat-function-in-simulink#comment_975393

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/580266-repmat-function-in-simulink#comment_975393

great help. thank you. I see that bsxfun is for element.wise operation. if the operation was not element wise like "A\b", I assume the best way is arrayfun, isn't it?

Walter Roberson on 17 Aug 2020

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/580266-repmat-function-in-simulink#comment_975459

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/580266-repmat-function-in-simulink#comment_975459

If you repmat to create A for A\b then the array will be singular.

If you repmat to create rows of b then that could be valid. You would not use arrayfun for that.

If you repmat to create columns of b then it would be more efficient to instead repmat the output, as the \ operator will give the same results for all columns of b that are identical columns.

hosein Javan on 17 Aug 2020

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/580266-repmat-function-in-simulink#comment_975471

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/580266-repmat-function-in-simulink#comment_975471

Walter Roberson can you please answer me in this question?

https://www.mathworks.com/matlabcentral/answers/580521-fastest-way-to-apply-a-b-on-each-matrix-page#toggle-comments

Walter Roberson on 17 Aug 2020

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/580266-repmat-function-in-simulink#comment_975477

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/580266-repmat-function-in-simulink#comment_975477

Edited: Walter Roberson on 5 Nov 2020

No, I cannot answer that question. See https://www.mathworks.com/matlabcentral/answers/29574-automatic-detection-of-melanoma#answer_37922

Rubem Pacelli on 5 Nov 2020

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/580266-repmat-function-in-simulink#comment_1111320

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/580266-repmat-function-in-simulink#comment_1111320

Man... What is the answer to my question?

Walter Roberson on 5 Nov 2020

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/580266-repmat-function-in-simulink#comment_1111490

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/580266-repmat-function-in-simulink#comment_1111490

Open in MATLAB Online

Use a selector block. Choose 2 dimensions for input. For your first dimension, tell it to select all. For your second dimension, tell it to use a vector from dialog. In the dialog space, enter

repmat(1:2, 1, Ns)

assuming here that the size of the second dimension is 2.

Now connect a reshape() block to the output of that, and specify output dimensions [1, 2, Ns*2]

Rubem Pacelli on 5 Nov 2020

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/580266-repmat-function-in-simulink#comment_1113195

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/580266-repmat-function-in-simulink#comment_1113195

Edited: Rubem Pacelli on 5 Nov 2020

Thank you! I think you meant to say [1, 2, Ns] instead of [1, 2, Ns*2]. Before the reshape I have a [1x2*Ns] vector. Hence, it is not possible to reshape to [1, 2, Ns*2]. When I put [1, 2, Ns] in a reshape block, I got a matrix in a shape that I was looking for. :)

Walter Roberson on 5 Nov 2020

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/580266-repmat-function-in-simulink#comment_1113205

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/580266-repmat-function-in-simulink#comment_1113205

Yes, you are right, [1, 2, Ns]

Sign in to comment.

Sign in to answer this question.

Accepted Answer

Ivan Garcia on 30 Jul 2021

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/580266-repmat-function-in-simulink#answer_757427

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/580266-repmat-function-in-simulink#answer_757427

Edited: Ivan Garcia on 30 Jul 2021

You can model the repmat function used in the MATLAB function block above in Simulink as follows:

If the input array "u" has 2 dimensions feed it into a "Reshape" block. Set the output dimensionality to "Customize" and then set the output dimensions to: [1, XSize, YSize], where XSize and YSize are the dimension sizes of the original array. This will expand the third dimension. Then feed the output of the reshape block into a "Selector" block. Set the number of input dimensions to 3. Then for the first dimension set the index option to "Index vector (dialog)" and set the index value to "ones(1, Ns)". For the other two dimensions set the index option to "Select all".

Hope this helps.

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

More Answers (0)

Sign in to answer this question.

See Also

Categories

SimulinkSimulink Environment FundamentalsBlock LibrariesSources

Find more on Sources in Help Center and File Exchange

Tags

  • simunlink
  • repmat

Products

  • Simulink

Release

R2020a

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


repmat function in Simulink (19)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

repmat function in Simulink (2024)
Top Articles
Latest Posts
Article information

Author: Nathanael Baumbach

Last Updated:

Views: 5375

Rating: 4.4 / 5 (75 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Nathanael Baumbach

Birthday: 1998-12-02

Address: Apt. 829 751 Glover View, West Orlando, IN 22436

Phone: +901025288581

Job: Internal IT Coordinator

Hobby: Gunsmithing, Motor sports, Flying, Skiing, Hooping, Lego building, Ice skating

Introduction: My name is Nathanael Baumbach, I am a fantastic, nice, victorious, brave, healthy, cute, glorious person who loves writing and wants to share my knowledge and understanding with you.