How do I create an Array of random binary?

Essentially, I have ten matrices in my array of 60x96x10 and for each matrix I need to have random binary numbers, but the indices of the 1's cannot repeat through the array and each of the 60x96 needs to have a one only once.

댓글 수: 5

Image Analyst
Image Analyst 2015년 8월 3일
편집: Image Analyst 2015년 8월 3일
I don't understand. If you have 60 by 96 matrixes, and 10 slices of those, then in any given vertical column through the slices in the "z" direction, the "1" can appear at a slice number of 1 through 10. So you can only have 10 vertical columns that have unique slice values before you'll need to repeat a slice value. So what does "cannot repeat" mean to you?
tash7827
tash7827 2015년 8월 3일
It means that when you slice in the "z" direction, anywhere you do it, 1 will appear once and only once.
Jan
Jan 2015년 8월 3일
The question is not clear: Do you have 10 ones finally, or 60*96?
tash7827
tash7827 2015년 8월 3일
sorry - yes i have 60*96 ones
Image Analyst
Image Analyst 2015년 8월 3일
tash, if you have 10 slices and only one "1" in each slice, then you will have only 10 1's, not 60x96. If you do have 60x96 ones, then you MUST have some z slices that have more than one 1 in them. If you didn't then you'd have only 10 1's, not 60x96 of them.

댓글을 달려면 로그인하십시오.

답변 (2개)

Jan
Jan 2015년 8월 3일

0 개 추천

Perhaps you want 10 unique numbers in the range of 1:60*96 as indices?
Index = randperm(1:60*96, 10);
Result = zeros(60, 96, 10);
Ind = sub2ind([60*96, 10], Index, 1:10);
Result(Ind) = 1;

댓글 수: 1

tash7827
tash7827 2015년 8월 3일
thank you for this response but i would like 60*96 ones finally, so how would i tweak this response?

댓글을 달려면 로그인하십시오.

Jon
Jon 2015년 8월 3일
편집: Jon 2015년 8월 3일

0 개 추천

M = zeros(60,96,10);
for j = 1:size(M,3)
rand_row_idx = randi([1 size(M,1)]);
rand_col_idx = randi([1 size(M,2)]);
M(rand_row_idx,rand_col_idx,j) = 1;
end
Edit: just saw that you want 60*96 ones finally; this is for 10 ones. For 5760 ones, you can use
M = zeros(60,96,10);
for j = 1:size(M,1)
for jj = 1:size(M,2)
rand_z = randi([1 size(M,3)]);
M(j,jj,rand_z) = 1;
end
end

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2015년 8월 3일

댓글:

2015년 8월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by