Generate random number between a given sequence using rand and exisiting matrix

조회 수: 1 (최근 30일)
Kash022
Kash022 2016년 9월 26일
댓글: Kash022 2016년 9월 26일
Hello,
Is there a way I can generate a random number vector of dimensions N*M*K between a given defined sequence? For example, I would like to generate a 256*2500*16 matrix and the elements of this matrix should be say between the values,8e-4 and 2.5e-8? I have tried to use the rand function with the 'like' option but don't see how to generate between that sequence.
my_needed_matrix = rand(size(my_existing_matrix),'like',my_existing_matrix);
Here my_existing_matrix is the matrix which from which I wish to create another matrix of similar values.
Thank you!
  댓글 수: 1
Adam
Adam 2016년 9월 26일
You haven't given any information as to how your existing matrix is supposed to contribute to the solution other than by giving its size which is rather trivial. Based on the information you have given Andrei's answer and your plot of it gives exactly what I would expect from your question.

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

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2016년 9월 26일
편집: Andrei Bobrov 2016년 9월 26일
a = 2.5e-8;
b = 8e-4;
my_needed_matrix = rand(size(my_existing_matrix))*(b - a)+a;
Please read MATLAB Documentation about it.
  댓글 수: 6
Kash022
Kash022 2016년 9월 26일
Its a huge mat file ~ 71MB. so I don't think its possible to attach it here. my_existing_matrix is a 256*2500*16 double
Kash022
Kash022 2016년 9월 26일
The trace exists between points 500 and ~650..so I tried to write this
out(t(:,500:650,:)) = rand(sum(t),1)*6e-5 + 1.5e-5;
but it still returns the previous error. So you see, between these two points I need something which rises upto say 575, and then decreases to zero for the other half.

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

카테고리

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