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.

 Accepted Answer

Perhaps ?
v = 1 : 24;
[x,y]=ndgrid(v);
Result=[x(:) y(:)];
Result=Result(randperm(272),:)

5 Comments

for i=1:272
if(Result(i,1)==Result(i,2))
x=4;
end
end
I used it to see if there are equal numers in 1 and 2 and there are ;/
Andrzej Nowak
Andrzej Nowak on 12 Jan 2019
Edited: Andrzej Nowak on 12 Jan 2019
Maybe i will explain what am I doing. I create poker machine. In poker players have 2 cards on hand. There are 2 players and cards are from 9 to Ace.
In my program i describe my cards as numbers from 1 to 24. Program starts when there is a flop(3 cards on table). Than it comes 4th card and 5th card on table. When there are 2 players with 2 cards and flop has 3 cards there are 7 cards that we know. I made table where are this cards. Now i need add to this table possible cards on turn(4th card on table) and river(5th card on table). They cannot be the same so there are 272 possibilities because 24-7 = 17. 17*16=272.
clear all
v = 1 : 24;
[x,y]=ndgrid(v);
Result=[x(:) y(:)];
Result=Result(randperm(size(Result,1)),:);
Final=Result(Result(:,1)~=Result(:,2),:);
Final=Final(randperm(272),:) % desired result
any(Final(:,1)==Final(:,2)) % to check if any column repetitions occur
any(ismember(a(1:2:end,:),a(2:2:end,:),'rows')) % to check if any row repetitions occur
size(Final) % desired size
Thank you very much. I will test it.
Anytime :) , sure!

Sign in to comment.

More Answers (2)

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
Andrzej Nowak on 12 Jan 2019
Edited: Andrzej Nowak on 12 Jan 2019
This is (34:2) array. (2,1) =10 (1,1) = 5 . As yo can see on 18 possition there are two 2 and i dont want this.
I used p=randi (17,272,2);
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
Andrzej Nowak on 12 Jan 2019
Edited: Andrzej Nowak on 12 Jan 2019
it doesn't work i need exacly 272 combines of cards. and when i use it the number is not always 272.
With your idea there can be the same rows eq 1 2 and 1 2 .idk how to eliminate them.

Sign in to comment.

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

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!