How can I solve randperm error with words?
Ältere Kommentare anzeigen
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 Kommentare
Rik
am 24 Mai 2019
You forgot to keep the middle line that Stephen gave you:
X = nchoosek(1:numel(Tile),2);
Martha Spadaccino
am 24 Mai 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
am 24 Mai 2019
Akzeptierte Antwort
Weitere Antworten (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 Kommentare
Martha Spadaccino
am 24 Mai 2019
KSSV
am 24 Mai 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
am 24 Mai 2019
Kategorien
Mehr zu Shifting and Sorting Matrices finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!