一:問題 有兩個(gè)規(guī)模相同的數(shù)組,,兩個(gè)數(shù)組相同位置的元素一一對應(yīng),,現(xiàn)在要將兩數(shù)組的元素同時(shí)打亂順序,并且亂序后的兩數(shù)組對應(yīng)位置元素要保持亂序前的對應(yīng)關(guān)系,。 二:方法 采用randperm()函數(shù),,產(chǎn)生隨機(jī)種子,然后按隨機(jī)種子重新排序,,即得到排序后的數(shù)組,。 三,、實(shí)例 >> A=rand(5,2) A = 0.1232 0.1982 0.5044 0.6723 0.3473 0.4315 0.0921 0.6944 0.1478 0.2568 >> randIndex = randperm(size(A,1)) randIndex = 1 3 2 5 4 >> A_new=A(randIndex,:) A_new = 0.1232 0.1982 0.3473 0.4315 0.5044 0.6723 0.1478 0.2568 0.0921 0.6944 參考鏈接:http://www./thread-126212-1-1.html http://blog.csdn.net/u013476464/article/details/41595209 |
|