필터 지우기
필터 지우기

can you tell me more about 'repmat'?

조회 수: 2 (최근 30일)
pinak parida
pinak parida 2013년 8월 11일
more than matlab help.
like
what it does?
why it required?
how it works?
and other aspects you know.
and also any codeor code module in general matlab we can use in place of "repmat".
plz explain in detail.

채택된 답변

Walter Roberson
Walter Roberson 2013년 8월 11일
You can look at the source code for repmat. It is roughly:
let N be the size() of the array along the dimension in question. Construct M = 1:N (vector of indices). Now if the array is to be repeated P times, construct a vector Q which is P copies of M appended to each other. Once you have that, index the original array at Q
for example, if the array is of length 2 repeated 3 times, then you would construct Q = [1 2 1 2 1 2], and then index array(Q,:) which is array([1 2 1 2 1 2], :)
There is no magic to it, just brute force indexing to repeat an array a number of times. There are a lot of different reasons one might want to do that.
  댓글 수: 3
Walter Roberson
Walter Roberson 2013년 8월 13일
That is like asking what the reasons are that one might want to multiply.
I will give an example of a less common use:
Suppose you need to construct a format string for use with textscan(). The number of elements that will be on one line is, in this example, not known ahead of time, but is known at the time one wants to construct the format string. Each format element can (in this example) be written as '%d'. Suppose the number of entries on the line is given by the variable N. Now how do you construct the string '%d%d%d%d...%d' where there are N copies of the '%d' ?
You could use a loop to construct the string. You could get fancy and do binary decomposition of N in order to find the way to construct the string using the fewest concatenation operations. Or you can go for simplicity and use repmat(): repmat('%d', 1, N)
There are many many other uses for repmat.
pinak parida
pinak parida 2013년 8월 14일
thankyou

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by