Replace matrix with the other random matrix.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Andi Tarigan
am 27 Jan. 2014
Bearbeitet: Walter Roberson
am 16 Apr. 2016
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
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))
Akzeptierte Antwort
Amit
am 27 Jan. 2014
Bearbeitet: Amit
am 27 Jan. 2014
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
Amit
am 27 Jan. 2014
rng(0);
arnold_new_null = rand(1024,1);
rng(1);
arnold_new_one = rand(1024,1);
Weitere Antworten (1)
Azzi Abdelmalek
am 27 Jan. 2014
Maybe you want this:
a=randi([0 1],1,10);
s=rng;
b=rand(1,10);
out=a.*b
3 Kommentare
Azzi Abdelmalek
am 27 Jan. 2014
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)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!