How to generate array (x:2)
Show older comments
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.
Accepted Answer
More Answers (2)
Image Analyst
on 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 Comments
Andrzej Nowak
on 12 Jan 2019
Edited: Andrzej Nowak
on 12 Jan 2019
Image Analyst
on 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
on 12 Jan 2019
Edited: Andrzej Nowak
on 12 Jan 2019
Image Analyst
on 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, :)
Categories
Find more on Card games in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!