Replace matrix with the other random matrix.

Hello,
Here I have matrix vector 0 and 1 with size (1024, 1), and I have the other matrix from random matrix with value between 0 and 1, with a seed (rng function), so the output of this matrix not change, and length this matrix dependent how much vector 0 and 1 in the first matrix. And I want to replace the first matrix (1024, 1) with the second matrix, but must equal with the vector, 0 or 1. And the output matrix which changed have the value random (between 0 until 1) with size (1024, 1). How can I make it? Thank you.

2 Kommentare

Amit
Amit am 27 Jan. 2014
The question is a bit confusing. Can you rephrase it with an example (probably take the matrix as size (5,1))
Andi Tarigan
Andi Tarigan am 27 Jan. 2014
Bearbeitet: Walter Roberson am 16 Apr. 2016
arnold_new = reshape(arnold, 1024, 1); % Make the matrix to 1 column
find_0 = find(arnold_new == 0); % Total bit 0
find_1 = find(arnold_new == 1); % Total bit 1
size_0 = size(find_0);
size_1 = size(find_1);
% =========================================================================
% Program to generate pseudorandom bit 0
% =========================================================================
rng(0) % Seed for bit 0
null = rand(size_0); % Total random value bit 0
null_new = reshape(nol, length(null_new), 1); % Make matrix to 1 column
% =========================================================================
% Program to generate pseudorandom bit 0
% =========================================================================
rng(1)% Seed for bit 1
one = rand(size_1); % Total random value bit 0
one_new = reshape(one, length(one_new), 1); % Make matrix to 1 column
And how i can changed the arnold_new matrix with the pseudorandom sequence in null_new and one_new? So that output is random, not bit 0 or 1 as arnold_new.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Amit
Amit am 27 Jan. 2014
Bearbeitet: Amit am 27 Jan. 2014

0 Stimmen

How about simply:
rng(0);
arnold_new_null = rand(size(arnold_new));
rng(1);
arnold_new_ones = rand(size(arnold_new));
arnold_new(arnold_new == 1) = arnold_new_ones(arnold_new == 1);
arnold_new(arnold_new == 0) = arnold_new_nulls(arnold_new == 0);

7 Kommentare

Andi Tarigan
Andi Tarigan am 27 Jan. 2014
And how about the matrix arnold_new (with bit 0 and 1)? Because I want to replace it, with the arnold_new_null and arnold_new_one.
Amit
Amit am 27 Jan. 2014
So If I understand you correctly, you want to replace 1s with random number generated by seed 1 and 0s with random number generated by seed 0.
Check the updated code if thats what you want.
Andi Tarigan
Andi Tarigan am 27 Jan. 2014
Until arnold_new_null and arnold_new_ones are correct. I am sorry, i mean matrix arnold_new replace by seed 1s and 0s, must be matched with arnold_new_null and arnold_new_ones. So, if the first row is bit 0, it will replaced by first row arnold_new_null, and if the second row is bit 1, it will replaced by first row arnold_new_ones. So the total row in arnold_new = arnold_new_null + arnold_new_ones
Okay. That is clear. This will work.
nullVals = find(arnold_new == 0);
onesVals = find(arnold_new == 1);
rng(0);
arnold_new(nullVals) = rand(length(nullVals),1);
rng(1);
arnold_new(onesVals) = rand(length(onesVals),1);
Andi Tarigan
Andi Tarigan am 27 Jan. 2014
Bearbeitet: Andi Tarigan am 27 Jan. 2014
It's work, but I must change that to:
rng(0); arnold_new_null = rand(length(nullVals),1); rng(1); arnold_new_one = rand(length(onesVals),1);
And how if I want to make both to 1 column? But with the same sequence,so the size is 1024,1.
rng(0);
arnold_new_null = rand(1024,1);
rng(1);
arnold_new_one = rand(1024,1);
Andi Tarigan
Andi Tarigan am 27 Jan. 2014
Okay. Thankyou sir!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Azzi Abdelmalek
Azzi Abdelmalek am 27 Jan. 2014

0 Stimmen

Maybe you want this:
a=randi([0 1],1,10);
s=rng;
b=rand(1,10);
out=a.*b

3 Kommentare

Andi Tarigan
Andi Tarigan am 27 Jan. 2014
Thanks sir, but I must have 2 rng, for bit 0 and bit 1. If the first row in matrix a is 1, it must take a random from matrix b (rng for 1). Same with bit 0, it will take from matrix b (rng for 0). So I can replace matrix a, with matrix b.
a=randi([0 1],1,10);
s1=rng;
b1=rand(1,10);
s2=rng;
b2=rand(1,10);
out=zeros(size(a))
out(a==1)=b1(a==1)
out(a==0)=b2(a==0)
Andi Tarigan
Andi Tarigan am 27 Jan. 2014
It works! Thankyou sir!

Melden Sie sich an, um zu kommentieren.

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by