Repetition of element in matrix

1 回表示 (過去 30 日間)
Danish Nasir
Danish Nasir 2021 年 9 月 4 日
コメント済み: Walter Roberson 2021 年 9 月 4 日
Suppose i have a matrix A=[23 17]
I want to proportion element of A in such a way that sum will remains equal to elemental value of A.
E.g 23 can be proportion to 8 8 7 . Similarly 17 can be 7 7 3
Hence final matrix will be B= [8 8 7 7 7 3]
I am trying to use repelem function but it requires equal proportion of elemets.
How to generate B matrix?

採用された回答

Walter Roberson
Walter Roberson 2021 年 9 月 4 日
If you are looking for random values, then see https://www.mathworks.com/matlabcentral/answers/327656-conditional-random-number-generation#answer_257296 which has code written by someone who put a lot of thought into making the process "fair"
  2 件のコメント
Danish Nasir
Danish Nasir 2021 年 9 月 4 日
Actually i have a proportion matrix P by which i have to proportion the elements. This proportion will have all equal element except last element.
E.g P=[3 4]. Now 23 to be divided in 3 proportion of which 2 proportions are to be equal, so it will be 8 8 3. Similarly 17 will be divided by 4, then it will be 5 5 5 2.
hence final matrix B=[ 8 8 3 5 5 5 2]
Can you suggest how to generate code for matrix B?
Walter Roberson
Walter Roberson 2021 年 9 月 4 日
https://www.mathworks.com/matlabcentral/answers/1446644-repetition-of-elements-in-a-matrix#answer_780764
I already posted complete code.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by