Could anyone help me to solve the following issue

1 回表示 (過去 30 日間)
jaah navi
jaah navi 2019 年 6 月 3 日
コメント済み: KSSV 2019 年 6 月 3 日
Code:
a = [1 2 3 4 5;
6 7 8 9 10]
a_rand = a(randperm(length(a)))
When i run the above two commands it executes and gives the following result
a_rand = 3 6 2 7 1
But in this result i can get only one row .
Coud anyone help me how to get two rows with the left out numbers displaying at the second row.

回答 (2 件)

KSSV
KSSV 2019 年 6 月 3 日
a = [1 2 3 4 5;
6 7 8 9 10] ;
idx1 = (randperm(length(a))) ;
idx2 = setdiff(1:numel(a),idx1) ;
iwant = [a(idx1) ; a(idx2)]
  4 件のコメント
jaah navi
jaah navi 2019 年 6 月 3 日
reshape should be done with respect to the elements present in its own column.But when i used the above command it reshapes with respect to different column.could you please help me to solve this.
KSSV
KSSV 2019 年 6 月 3 日
[m,n] = size(a) ;
b = a ;
for i = 1:m
idx = randperm(n) ;
b(i,:) = a(i,idx) ;
end

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


TADA
TADA 2019 年 6 月 3 日
a = [1 2 3 4 5; 6 7 8 9 10]
a_rand = a(randperm(length(a)))
a_rand = [a_rand; a(~ismember(a(:),a_rand(:)))']
  3 件のコメント
TADA
TADA 2019 年 6 月 3 日
KSSVs reahape seems the best solution for your problem, unless you are looking for some other output
jaah navi
jaah navi 2019 年 6 月 3 日
but reshape makes use of reshaping from different column elements.
I want to reshape the elements present in its respective column.
For example
if
a= [4.7908 5.0104 5.1329 5.3186 5.3094 5.3070 5.4452 5.5001;
0.0958 0.0994 0 0 0.1848 0.2020 0.1851 0.2146;
0.0848 0 0.1469 0.1859 0.1767 0.1854 0.1856 0.1648;
0 0 0 0 0 0 0 0;
0 0.0896 0.1619 0.1351 0 0 0 0;
0 0 0 0 0 0 0 0]
the the output shoud be
a= [4.7908 0 0 5.3186 5.3094 5.3070 5.4452 0;
0 0.0994 0 0 0 0 0.1851 0.2146;
0.0848 0 0.1469 0.1859 0 0.1854 0 0.1648;
0.0958 0 0 0 0 0 0 5.5001;
0 0.0896 0.1619 0 0.1848 0.2020 0 0;
0 5.0104 5.1329 0.1351 0.1767 0 0.1856 0]
in the following random manner.

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

カテゴリ

Help Center および File ExchangeLanguage Fundamentals についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by