randperm and sorting array

9 vues (au cours des 30 derniers jours)
maharani meidy
maharani meidy le 25 Oct 2017
Commenté : maharani meidy le 25 Oct 2017
as example :
A = [8 9 0]
Perm1 = randperm(length(A));
B= A(:,Perm1);
B_eks=B
[val_sort, id_sort] = sort(Perm1);
A_eks = B_eks(:,id_sort);
i want it for looping, so A_eks(:,:,1) = [8 9 0],;A_eks(:,:,2) = [8 9 0],A_eks(:,:,2) = [8 9 0],A_eks(:,:,4) = [8 9 0], i have try like this:
for i=1:4
Perm1(:,:,i) = randperm(length(A));
B(:,:,i)= A(:,Perm1(:,:,i));
B_eks(:,:,i)=B(:,:,i)
end
for k=1:4
[val_sort, id_sort] = sort(Perm1(:,:,k));
A_eks(:,:,k) = B_eks(:,id_sort);
end
but it didn't work like i want, what should i do ?
  6 commentaires
KSSV
KSSV le 25 Oct 2017
If you want it to be same..keep it same....why to run all the stuff? Using randperm is good if you want to permute array randomly.
maharani meidy
maharani meidy le 25 Oct 2017
@KSSV : well.. i want it to be more secure than just keep it the same...^^

Connectez-vous pour commenter.

Réponse acceptée

KL
KL le 25 Oct 2017
Change
A_eks(:,:,k) = B_eks(:,id_sort);
to
A_eks(:,:,k) = B_eks(:,id_sort,k);
  1 commentaire
maharani meidy
maharani meidy le 25 Oct 2017
thank you ^^

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by