Scatter plot random values

I have got a array of random variables: A=rand(1,25);
I have to scatter plot A within X and Y axis. The limits of both X axis and Y axis are 0 to 1. There is no relation between the random variables A and X,Y axis.
How can I do this? If at all this is possible, how can I obtain the x and y coordiantes of the 25 points that have been plotted?
Please help.
Thanks in advance.

9 Comments

Currently, A=rand(1,25) is a 1D array. Are you trying to plot 25 random points in 2D X-Y?
If so:
A = rand(2,25);
X = A(1,:);
Y = A(2,:);
scatter(X,Y)
Alternatively:
X = rand(1,25);
Y = rand(1,25);
scatter(X,Y)
Thanx a lot.
Thanx Optics Wizard for the answer, but my problem is somewhat different. Let me explain:
I have got a few points, suppose:
A=[0.880337860379200 0.471101865015748 0.403969372170941 0.179231476423447 0.968924996147292 0.407455737802620 0.844487396483448 0.615325097130850 0.376611078032737 0.877181749337097 0.784852427283024 0.464954283314534 0.813976926820934 0.898444137180120 0.429238543114827];
I want to scatter these points in a 2D map in a random fashion. The X axis range is from 0 to 1 and Y axis range is from 0 to1. The A matrix I got is by using an optimization algorithm. Now I want to randomly scatter these points in a 2D graph. From there I want to obtain the coordinates assigned to the points.
I dont know if it is possible. If possible please help.
Thank You again.
x = rand(size(A));
y = rand(size(A));
%A(J,K) got scattered to X(J,K), Y(J,K)
The second code example should work for you. What do you want to do with the values of A? Nothing? Or should they be used as text labels?
Thank You. I will try the codes. On obtaining these points on the graph, I will be finding the Euclidean distance between the points plotted.
joel malcolm
joel malcolm on 6 Sep 2022
Moved: Rik on 6 Sep 2022
Hi Im trying to place random points inside a rectangular area that has a curve through the graph. I have doen this but plotting this on a graph is not working
What exactly did you try and how is that different from what you want? You should probably post your own question instead of trying to hijack this one.
Have a read here and here. It will greatly improve your chances of getting an answer.
You could get John d'Errico's interparc from the file exchange. Describe the curve by a series of line segments. Now generate the appropriate number of random points in the range 0 to 1 times the length of the curve, and interparc to find out the x y coordinates where those points fall. The points will be in random locations and they will be somewhere along the curve as required.

Sign in to comment.

Answers (0)

Products

Release

R2016a

Asked:

on 9 Apr 2020

Commented:

on 6 Sep 2022

Community Treasure Hunt

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

Start Hunting!