Borrar filtros
Borrar filtros

How can i generate 3 random points within a 2x2m grid?

2 visualizaciones (últimos 30 días)
Sohail Essajee
Sohail Essajee el 13 de Nov. de 2019
Comentada: ME el 13 de Nov. de 2019
Hello, i need to generate 3 points that are at random positions within a square boundary which is of 2x2m. I want these 3 points (wires) to also have random current values. I tried doing x=rand(1,3)*2 and y=rand(1,3)*2 but i need the graph to have 0 at the center and go from 1 to -1 on each axis. how can i do this?

Respuestas (1)

ME
ME el 13 de Nov. de 2019
I think you were on the right lines but you need to subtract one from your x and y:
x=rand(1,3)*2-1;
y=rand(1,3)*2-1;
That'll put all of your values in the range -1 to 1.
  2 comentarios
Sohail Essajee
Sohail Essajee el 13 de Nov. de 2019
Thank you, I just managed to get the graph right by specifying the limits using the axis command. So when it plots, there will be three random points within the graph which will represent my wires. but, how will i get random current values for these points? The graph is just a square boundary, so none of the axis will hold current within them.
ME
ME el 13 de Nov. de 2019
Apologies, I don't think I understand the question.
Can't you just generate another variable using rand as you did before. As previously, this will generate random numbers in the range 0-1 so you can always multiply these by whatever you want to get them in the correct range for your current.
If the question is more related to the plotting the you could use plot3 which would allow you to get your current as the value on the z-axis?

Iniciar sesión para comentar.

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by