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 (최근 30일)
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개)

Jan
Jan 2018년 1월 13일
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
Jenny
Jenny 2018년 1월 14일
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 2018년 1월 14일
편집: Jan 2018년 1월 14일
@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)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Preprocessing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by