How can I solve randperm error with words?
Show older comments
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 Comments
Rik
on 24 May 2019
You forgot to keep the middle line that Stephen gave you:
X = nchoosek(1:numel(Tile),2);
Martha Spadaccino
on 24 May 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
on 24 May 2019
Accepted Answer
More Answers (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 Comments
Martha Spadaccino
on 24 May 2019
KSSV
on 24 May 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
on 24 May 2019
Categories
Find more on Shifting and Sorting Matrices in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!