This question is closed. Reopen it to edit or answer.
here I am trying to get the random matrix with the elements only 1 and 0 where none of columns and rows can be 0 only and also the number of 0s and 1s should be in a percentage of 30% and 70%.
1 view (last 30 days)
Show older comments
gkboy on 7 Aug 2018
Closed: MATLAB Answer Bot on 20 Aug 2021
I am trying to get the random matrix with the elements only 1 and 0 where none of columns and rows can be 0s only or 1s only, and also the number of 0s and 1s should be in a percentage of 30% and 70%. They have to use probability
- Random Matrix
- elements only 1s and 0s
- percentage of 0s: 1s is 3:7
- None of the columns and rows can be with only 0 and only 1. have to have mix
Image Analyst on 8 Aug 2018
N=5; % size
z=zeros(N); % start w/ none
o=randperm(numel(z),fix(numel(z)/2)); % 30% < ~50% < 70%
z(o)=1; % set the ones
>> ok=~(any(all(z) & all(z,2).')) % did we meet criteria?
Yeah, the logic for the ok test isn't complete; the particular case was ok by inspection; it likely isn't a realistic ploy for practice; just a throwaway and probably shouldn't'a bothered...
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!