If i compute
repmat((1:n*N),6,1)
with n=3 and N=3 the complier gives me a 6X9 matrix.
Why if a create a
repmat (6,(1:n*N),1)
it gives me a 9-D double?
  1. 9-D is nine dimensions?
  2. What the compiler is doing?

4 件のコメント

Stephen23
Stephen23 2017 年 5 月 30 日
編集済み: Stephen23 2017 年 5 月 30 日
1. If you want to know what repmat is doing why not simply read the repmat documentation? Is it too difficult to find? (I tried [famous internet search engine] and it took 0.0001 seconds to find the repmat page)
If you had read the documentation then you would learn that the repetitions can be input as a vector, and because you specified nine elements (the tenth being one) you generate a nine dimensional array.
2. What compiler?
Rik
Rik 2017 年 5 月 30 日
Fun fact, I looked at the documentation from a few random old releases and I couldn't find how repmat parses a mix of vector and scalar inputs, but the warning suggests it simply concatenates them.
Steven Lord
Steven Lord 2017 年 5 月 30 日
That's correct, based on the Release Notes for release R2013b, when we introduced those warnings (and errors) for certain types of repmat calls including repmat(A, b, c) where b and c are row vectors (that are not both scalar.)
Andrea Ciufo
Andrea Ciufo 2017 年 5 月 30 日
編集済み: Andrea Ciufo 2017 年 5 月 30 日
Yep, in fact my two questions was a confirm on what i thought, but, sure, i read the documentation before asking, not only once :) Since i am a self taught i prefer to ask silly questions for a senior instead of learning the wrong concept :)

サインインしてコメントする。

 採用された回答

Rik
Rik 2017 年 5 月 30 日

2 投票

Have you even considered looking at the documentation? It really helps answering your question.
Looking at the documentation, I could find how supplying a vector as the second argument would work, but I get a warning. "repmat(A,M,N) where M or N is a row vector will return an error in a future release. Use repmat(A,[M,N]) instead." This hints at what is happening: it concatenates all inputs into 1 vector.
The first argument is the scalar/vector/matrix that you want to replicate. Then you have 3 options:
  1. using 1 value, which will result in that many replications in the first two dimensions (rows and cols)
  2. using 1 vector, which specifies the number of replications in each dimension (e.g. [1 1 3] will replicate a value/vector/matrix into the 3rd dimension, useful for going from greyscale to RGB images)
  3. splitting the vector over separate arguments
Knowing this it is obvious why your results are what they are. The first replicates a 1x9 vector (1:9) 6 times in the first dimensions (the rows), so you get a 6x9. The second replicates a scalar (so 1x1), using [1:9,1] as the repetition scheme, so the result is a 1x2x3x4x5x6x7x8x9x1 matrix, which is an 9-dimensional matrix (as any trailing x1 can be ignored).

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

質問済み:

2017 年 5 月 30 日

編集済み:

2017 年 5 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by