How to create random vectors of the same lengths?

Illustration
kellysmith9 - 2020-09-02T11:33:59+00:00
Question: How to create random vectors of the same lengths?

I am trying to get a random vector (2D) of the same length, say 'x'. I thought about creating a list of numbers -1 to 1 for x values and then another one for from 1 to -1 for y values, and then randomly picking two numbers from the list, but this would give me vectors of all lengths and I don't know how to normalize them. I had all sorts of other ideas but none of them seem to be of much use.

Expert Answer

Profile picture of Prashant Kumar Prashant Kumar answered . 2025-11-20

from the documentation: Examples
Generate values from the uniform distribution on the interval [a, b].
 
 r = a + (b-a).*rand(100,1);

in your case you'd want:

 a = min + (max-min).*rand(N,2);


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!