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"?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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.
1 comentario
Stephen23
el 14 de En. de 2018
You should avoid magically accessing variable names. Read this to know why:
Respuestas (1)
Jan
el 13 de En. de 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:
- https://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval
- https://www.mathworks.com/matlabcentral/answers/57445-faq-how-can-i-create-variables-a1-a2-a10-in-a-loop
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 comentarios
Jan
el 14 de En. de 2018
Editada: Jan
el 14 de En. de 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)
Ver también
Categorías
Más información sobre Data Preprocessing 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!