Generate random number between a given sequence using rand and exisiting matrix
Mostrar comentarios más antiguos
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 comentario
Adam
el 26 de Sept. de 2016
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.
Respuestas (1)
Andrei Bobrov
el 26 de Sept. de 2016
Editada: Andrei Bobrov
el 26 de Sept. de 2016
a = 2.5e-8;
b = 8e-4;
my_needed_matrix = rand(size(my_existing_matrix))*(b - a)+a;
6 comentarios
Kash022
el 26 de Sept. de 2016
Andrei Bobrov
el 26 de Sept. de 2016
Editada: Andrei Bobrov
el 26 de Sept. de 2016
Maybe so? (but here my_existing_matrix is vector as in your images):
out = zeros(numel(my_existing_matrix),1);
t = my_existing_matrix ~= 0;
out(t) = rand(sum(t),1)*6e-5 + 1.5e-5;
Andrei Bobrov
el 26 de Sept. de 2016
Editada: Andrei Bobrov
el 26 de Sept. de 2016
.. I wrote: ".. but here my_existing_matrix is vector as in your images" so that my_existing_matrix should be vector.
and please attach your data as mat - file what you getting in images.
Kash022
el 26 de Sept. de 2016
Kash022
el 26 de Sept. de 2016
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!