matlab赋值一行,matlab – 0和1的矩阵,其中后续行中的赋值取决于前一行

基于检查数字是大于还是小于中位数的解决方案.只要测试的列数是偶数,一组随机双精度的正好一半将大于中位数,一半将更小.这可以保证正好有50%的位被翻转.

nRows = 3;

nCols = 16; %# divisible by 4

%# seed the array

%# assume that the numbers in each row are unique (very, very likely)

array = rand(nRows,nCols);

out = false(nRows,nCols);

%# first row is special

out(1,:) = array(1,:) > median(array(1,:));

%# for the rest of the row, check median for the zeros/ones in the previous row

for iRow = 2:nRows

zeroIdx = out(iRow-1,:) == 0;

%# > or < do not matter, both will replace zeros/ones

%# and replace with exactly half zeros and half ones

out(iRow,zeroIdx) = array(iRow,zeroIdx) > median(array(iRow,zeroIdx));

out(iRow,~zeroIdx) = array(iRow,~zeroIdx) > median(array(iRow,~zeroIdx));

end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值