How can I solve randperm error with words?
Mostrar comentarios más antiguos
I had create this code
Tile = {'house', 'core', 'word', 'ask', 'question', 'horse', 'phone', 'eyes', 'hair', 'man'};
>> X = X(randperm(size(X,1)),:);
>> Error undefined function or variable X
I would have all possible random combinations pairs without repetitions and without have the same values (e.g horse - horse). How can I do?
4 comentarios
Rik
el 24 de Mayo de 2019
You forgot to keep the middle line that Stephen gave you:
X = nchoosek(1:numel(Tile),2);
Martha Spadaccino
el 24 de Mayo de 2019
"I want a random order.."
X = X(randperm(size(X,1)),:); % random row order.
Based on your question above, you are not runinng the complete code that i gave you. Exactly as Rik wrote, for some unknown reason you have decided to remove one lines of the code that I gave you. Of course it will not work if you remove a line of code!
This is the code I gave you, it does exactly as you requested (very efficiently!):
>> Tile = {'house', 'core', 'word', 'ask', 'question', 'horse', 'phone', 'eyes', 'hair', 'man'};
>> X = nchoosek(1:numel(Tile),2); % Why did you remove this?
>> X = X(randperm(size(X,1)),:);
>> Tile(X)
Martha Spadaccino
el 24 de Mayo de 2019
Respuesta aceptada
Más respuestas (1)
Tile = {'house', 'core', 'word', 'ask', 'question', 'horse', 'phone', 'eyes', 'hair', 'man'};
% Gives random arrangement
X = Tile(randperm(length(Tile)));
% get all posibilities
idx = perms(1:length(Tile)) ;
iwant = Tile(idx) ;
3 comentarios
Martha Spadaccino
el 24 de Mayo de 2019
KSSV
el 24 de Mayo de 2019
YOu got nothing because the out put is terminated with ;
In the code iwant gives you all the possible permutations of the cell array tile.
Check:
iwant(1:10,:)
Martha Spadaccino
el 24 de Mayo de 2019
Categorías
Más información sobre Shifting and Sorting Matrices en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!