How to generate array (x:2)
显示 更早的评论
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.
采纳的回答
更多回答(2 个)
Image Analyst
2019-1-12
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 个评论
Andrzej Nowak
2019-1-12
编辑:Andrzej Nowak
2019-1-12
Image Analyst
2019-1-12
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
2019-1-12
编辑:Andrzej Nowak
2019-1-12
Image Analyst
2019-1-12
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, :)
类别
在 帮助中心 和 File Exchange 中查找有关 Card games 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
