How can i make a partition matrix

9 ビュー (過去 30 日間)
Jesus Montiel
Jesus Montiel 2019 年 11 月 9 日
回答済み: Praveen Iyyappan Valsala 2019 年 11 月 9 日
I tried to make a mxn partition matrix that all her columns sum 1.0, i have this, but is very slow
c=5; k=3;
matrixTemp = zeros(c, k);
randoms = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9];
idx_r = zeros(1,k);
for i = 1:c
s = 0;
while s ~= 1
idx_r = randperm(9,k);
s = sum(randoms(idx_r));
end
matrixTemp(i,:) = randoms(idx_r);
end
It is posible more easy?
The partition matrix is the same that fuzzy c means.
I need this for example:
c1 | 0.5 0.6 0.1
c2 | 0,2 0.2 0.5
c3 | 0.3 0.2 0.4
----------------------
R | 1.0 1.0 1.0 % sum each column equals to 1.0

採用された回答

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH 2019 年 11 月 9 日
If you are not interested in decimals, just add one, the solution is easy:
c=5;
k=3;
matrixTemp=rand(c,k);
matrixTemp=matrixTemp./sum(matrixTemp)
if you want the entire matrix to have only one decimal place :
c=5;
k=3;
while true
matrixTemp=rand(c,k);
matrixTemp=matrixTemp./sum(matrixTemp);
matrixTemp=round(matrixTemp*10)/10;
if prod(prod(matrixTemp))~=0
break;
end
end
disp(matrixTemp)
  1 件のコメント
Jesus Montiel
Jesus Montiel 2019 年 11 月 9 日
Thanks a lot, the first example works fine and faster.

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

その他の回答 (1 件)

Praveen Iyyappan Valsala
Praveen Iyyappan Valsala 2019 年 11 月 9 日
If you want to list all possible partitions. Not suitable for large k.
randoms = 0.1:0.1:0.9;
%Index of all permutations with repetitions
[k1,k2,k3] = ndgrid(1:length(randoms)) ; %manually type all k;)
allperm = [k1(:) k2(:) k3(:)] ;
% use the idex to set up permutation matrix of random
random_allperm=randoms(allperm);
%Pick the permuations with sum==1
AllPartitions=randoms(allperm((sum(random_allperm,2)==1),:));
%% pick c number of partitions according to your needs
c=5;
disp(AllPartitions(randperm(length(AllPartitions),c),:))

カテゴリ

Help Center および File ExchangeFuzzy Logic Toolbox についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by