필터 지우기
필터 지우기

Replace matrix with the other random matrix.

조회 수: 1 (최근 30일)
Andi Tarigan
Andi Tarigan 2014년 1월 27일
편집: Walter Roberson 2016년 4월 16일
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
Amit
Amit 2014년 1월 27일
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 2014년 1월 27일
편집: Walter Roberson 2016년 4월 16일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Amit
Amit 2014년 1월 27일
편집: Amit 2014년 1월 27일
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
Amit
Amit 2014년 1월 27일
rng(0);
arnold_new_null = rand(1024,1);
rng(1);
arnold_new_one = rand(1024,1);
Andi Tarigan
Andi Tarigan 2014년 1월 27일
Okay. Thankyou sir!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 1월 27일
Maybe you want this:
a=randi([0 1],1,10);
s=rng;
b=rand(1,10);
out=a.*b
  댓글 수: 3
Azzi Abdelmalek
Azzi Abdelmalek 2014년 1월 27일
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 2014년 1월 27일
It works! Thankyou sir!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by