repmat function in Simulink
이전 댓글 표시
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

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
hosein Javan
2020년 8월 16일
편집: hosein Javan
2020년 8월 16일
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
2020년 8월 16일
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
2020년 8월 16일
I do not agree that repmat is used for elementwise operations. That would be repelems
hosein Javan
2020년 8월 16일
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
2020년 8월 16일
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
2020년 8월 16일
I'm using 2016a, thanks for implying that. I'm just concerned that newer versions aren't too RAM-friendy!
Walter Roberson
2020년 8월 16일
bsxfun for earlier releases
hosein Javan
2020년 8월 17일
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
2020년 8월 17일
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
2020년 8월 17일
Walter Roberson can you please answer me in this question?
Walter Roberson
2020년 8월 17일
편집: Walter Roberson
2020년 11월 5일
No, I cannot answer that question. See https://www.mathworks.com/matlabcentral/answers/29574-automatic-detection-of-melanoma#answer_37922
Rubem Pacelli
2020년 11월 5일
Walter Roberson
2020년 11월 5일
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
2020년 11월 5일
편집: Rubem Pacelli
2020년 11월 5일
Walter Roberson
2020년 11월 5일
Yes, you are right, [1, 2, Ns]
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!