construct a function which randomly change one bit a column

Ok,im trying to write a function on matlab which can randomly change one bit per column in matrix, for example like , if i have have a 4*4 matrix , i wanna the out put has one bit changed for each column.
for convenience i set up all my data 0 and 1. and basic idea of 'change' is flip 0 to 1 or 1 to 0.
i start with round(rand(4,4)) to get a random matrix, but how can i write the rest of the function?

1 件のコメント

Walter Roberson
Walter Roberson 2012 年 9 月 4 日
How many bits per item? Double precision is 53 bits of precision, 10 bits of exponent, and 1 bit of sign, but with a small bit of work it can be changed to unsigned 64 bit integer -- but earlier MATLAB could not work with 64 bit unsigned integers properly.

サインインしてコメントする。

 採用された回答

Matt Fig
Matt Fig 2012 年 9 月 4 日
編集済み: Matt Fig 2012 年 9 月 4 日

0 投票

A = round(rand(4,4)); % The initial matrix.
% Given A, use this to change one random element per column.
[m,n] = size(A); % Just to be general...
idx = ceil(rand(1,n)*m)+(0:n-1)*m;
A(idx) = ~A(idx)

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by