Clear Filters
Clear Filters

How can I plot a series of points in a vector with two coordinates x&y considering that I want to name these points respectively S1, S2....S10, and I want to use them in other functions just by using their "name"?

2 views (last 30 days)
I want to plot a series of points in a vector with two coordinates x&y and I want to name these points respectively S1, S2....S10, and then I wantto use them in other functions just by using their "name". How can I write the code to be able to do this? The vector will be: S=[S1,S2,S3,S4,S5,S6,S7,S8,S9,S10] While the coordinates will be: x=[0 0.5 1 0.7 -1 -0.5 0.5 0.5 -0.5]; y=[1 -1 1 0.5 0 0.8 0.8 0 -0.8 -0.8]; I want to plot them with the respective letters, and then use them in functions just by typing the letter. Thank you in advance.

Answers (1)

Jan
Jan on 13 Jan 2018
This sounds like a rather complicated and indirect way of programming. Of course your could simply create a set of variables:
S1 = [0, 1]
S2 = [0.5, -1]
...
But as you find in many (hundreds!) discussions in this forum, this way is known to cause more troubles than it solves. Hiding indices in names of variables is not efficient, unclear and deprecated:
Using vectors and indices is the standard method and there are good reasons for this.
But to be honest, I'm not sure, what this exactly means:
I want to plot them with the respective letters, and then use them
in functions just by typing the letter
  8 Comments
Jenny
Jenny on 14 Jan 2018
It is supposed that in the center I have a sensor P with coordinates (0;0). P has a radius R=1. Then we have the distance of the other sensors from P, that will be r=sqrt(√(x^2+y^2)); Then we have a condition: If r-R<rho, rho=0.08, then the coordinates of the sensors (points) that fulfill the condition should be put in the final vector, and this vector should be printed as the result in the screen after the code execution. Can you help me please? I wrote a "code", but it doesn't give me any result.
Jan
Jan on 14 Jan 2018
Edited: Jan on 14 Jan 2018
@Jenny: If you post your code, the readers can suggest improvements. Sometimes it is easier to fix an existing code than to write it completely from scratch. Then we could e.g. know, how your inputs look like. Do you get the position of the other sensors as an array? Or do you use random points? Or an even grid of coordinates?
What about the code I had suggested already - with a tiny modification:
R = 1.0;
dist2 = sqrt(x .^ 2 + y .^ 2);
match = dist2 - R < 0.08; % Or abs(dist2 - R) < 0.08 ??
xm = x(match)
ym = y(match)

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!