Matlab如何随机分配矩阵元素

Matlab如何随机分配矩阵元素,matlab,matrix,distribute,Matlab,Matrix,Distribute,大家好,如何使一个矩阵随机分布到另一个矩阵n m = [ 1 1 3 3 3 4 4 6 6 7 7 7]; n = zeros(3,10); 序列中必须有相同的值,例如:4、7、7。所需的结果可能类似于{或其他组合): 谢谢你…如果我正确理解了你的问题,可能的解决办法是 m = [ 1 1 3 3 3 4 4 6 6 7 7 7]; n = zeros(3,10); p= randperm(numel(n)); % generate the random permutation n(p(1:

大家好,如何使一个矩阵随机分布到另一个矩阵n

m = [ 1 1 3 3 3 4 4 6 6 7 7 7];
n = zeros(3,10);
序列中必须有相同的值,例如:4、7、7。所需的结果可能类似于{或其他组合):


谢谢你…

如果我正确理解了你的问题,可能的解决办法是

m = [ 1 1 3 3 3 4 4 6 6 7 7 7];
n = zeros(3,10);
p= randperm(numel(n)); % generate the random permutation
n(p(1:length(m)))= m   % assign the elments of m to the elements with indices taken 
                       % from the first length(m) numbers of random permutation

如果我正确理解你的问题,可能的解决办法是

m = [ 1 1 3 3 3 4 4 6 6 7 7 7];
n = zeros(3,10);
p= randperm(numel(n)); % generate the random permutation
n(p(1:length(m)))= m   % assign the elments of m to the elements with indices taken 
                       % from the first length(m) numbers of random permutation

如果未对
m
元素的分布顺序施加任何约束,则可能有助于:

ridx = randsample( numel(n), numel(m) ); %// sample new idices for elelemtns
n(ridx) = m;

仔细观察,事情变得有点混乱。
要在
m
中识别序列及其范围,您可以:

idx = [1 find(diff(m)~=0)+1]; 
extent = diff([idx numel(m)+1]);  %// length of each sequence
vals = m(idx);  %// value of each sequence

一旦你有了序列及其长度,你就可以随机地将它们洗牌,然后沿着直线分布…

如果你没有对
m
元素的分布顺序施加任何约束,那么可能会有帮助:

ridx = randsample( numel(n), numel(m) ); %// sample new idices for elelemtns
n(ridx) = m;

仔细观察,事情变得有点混乱。
要在
m
中识别序列及其范围,您可以:

idx = [1 find(diff(m)~=0)+1]; 
extent = diff([idx numel(m)+1]);  %// length of each sequence
vals = m(idx);  %// value of each sequence

一旦你有了序列和它们的长度,你就可以随机地将它们洗牌,然后沿着直线分布……

你是否需要序列(
1,1
3
等)“保持在一起”?是的,它们保持在一起……相同的值可以在
n
的行中分割吗?也就是说
[…7;7……]
?不,它不能…它必须在同一行中…谢谢..如果
m
在一个序列中的值大于
大小(n,2)
?它将不适合一行…您需要序列(
1,1
3
等)来“保持在一起”吗是的,它们保持在一起…相同的值可以在
n
的行中分割吗?也就是说
[…7;7…]
?不,它不能…它必须在同一行中…谢谢..如果
m
的值大于
大小(n,2),该怎么办
在序列中?它不适合一行…谢谢你的回答,但是如何使相同的值保留在序列中?谢谢你…谢谢你的回答,但是如何使相同的值保留在序列中?谢谢。。。