How to generate array (x:2)
Afficher commentaires plus anciens
How to generate array (x:2) with numbers from 1:24 without 7 numbers that i will write myself and(x,1) cannot equal (y,2). There should be 17*16=272 possibilities, so array should be 272x2. Please help.
Réponse acceptée
Plus de réponses (2)
Image Analyst
le 12 Jan 2019
Not exactly sure I follow your description, but it sounds like setdiff() will be involved:
v = 1 : 24;
numbersToExclude = randperm(24, 7)
finalNumbers = setdiff(v, numbersToExclude)
I have no idea what array(x:2) means. Or (x, 1) and (y, 2) for that matter.
I also don't know why there should be more than one possibility unless you're going to scramble the numbers after you get them.
3 commentaires
Andrzej Nowak
le 12 Jan 2019
Modifié(e) : Andrzej Nowak
le 12 Jan 2019
Image Analyst
le 12 Jan 2019
If you don't want repeats in your array, m, I suggest you create a lot more than you need, like a hundred or a thousand rows instead of 34, then delete rows with repeats.
repeatRows = m(:, 1) == m(:, 2); % Find rows where col 1 = col 2
m(repeatRows = []; % Delete/remove those rows;
% Crop to the 34 that you need.
m = m(1:34, :);
Andrzej Nowak
le 12 Jan 2019
Modifié(e) : Andrzej Nowak
le 12 Jan 2019
Image Analyst
le 12 Jan 2019
Try this:
[x, y] = ndgrid(1:17, 1:17)
data = [x(:), y(:)];
repeatRows = data(:, 1) == data(:, 2); % Find rows where col 1 = col 2
data(repeatRows, :) = []; % Delete/remove those rows;
data is now 272 by 2 -- every possible combination with no repeats. If you want to scramble the order, you can use
% Scramble the order
order = randperm(size(data, 1));
data = data(order, :)
Catégories
En savoir plus sur Card games dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
