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!
