how to connect coordinates?

Hi...I have these values.
x=[1,2,3,4]
y=[-2,0,-3,2,52,21,23]
each value of x corresponds to more than one value of y.... I want to plot y against x so that on x will be on absciss and y will be on ordinates,,, but I can't do it with plot since I can't interpret it as a function. How can I do it? Thanks.

7 件のコメント

KSSV
KSSV 2020 年 5 月 26 日
What relation you expect between x and y?
Ani Asoyan
Ani Asoyan 2020 年 5 月 26 日
Actually it's like this.
I have a function with parameters that have single values and I have one parameter that has a vector of values. it's my x vector.
that function is polynomial, I obtain its roots for each value of x, but for some x, there is more than one root, so the roots I noted as y.
I want to connect dots, if it's impossible to do as a function, just to show what values of y I get in the case of particular value of x, is it possible?
Adam Danz
Adam Danz 2020 年 5 月 26 日
So, something like this? If not, please illustrate your goal.
x = [1 2 2 3 4 5 5 6];
y = [0 2 4 5 6 3 6 8];
plot(x,y, 'o')
grid on
Ani Asoyan
Ani Asoyan 2020 年 5 月 26 日
no, the length of variables are not the same, several y's may correspond to one x. I want to plot or scatter y against x
Adam Danz
Adam Danz 2020 年 5 月 26 日
How do we know which x's correspond to each y?
simon beaudet
simon beaudet 2021 年 3 月 19 日
did you find the solution
Walter Roberson
Walter Roberson 2021 年 3 月 19 日
You would need to store the multiple solutions in a cell array, such as
x = [1,2,3,4]
y = {[-2,0], -4, [-3, 2], [52,21,23]}
If you did something like that, then you would have a chance -- but you would have to define which members of the previous set got connected to which members of the next. For example, we can guess that maybe the -4 is to be connected to both the -3 and 2, but then should the -3 be connected to all three of 52, 21, 23, or should it be only connected to 52 (the first) and then the 2 (second) gets connected to the 21 and all left-over values (23) ? Or should the -3 be connected to the 52 and 21 ("adjacent") with the 2 connected to the 21 and 23 ? Or should the -3 be connected to all three and the 2 be connected to all three?
I would suggest to you that polynomials always have the same number of roots, but that sometimes the roots are not real-valued, and that it might instead make the most sense to replace the complex-valued ones with nan leaving the structure intact. This would make the most sense if the roots are in a consistent order, following the same branch in each case. For example, if you use the explicit formula for a cubic then you can choose each of the three forms and plot them individually, whereas if you use roots() then there is the possibility that the values might not be in consistent order, as roots potentially sorts according to (for example) increasing absolute magnitude.

サインインしてコメントする。

回答 (0 件)

カテゴリ

質問済み:

2020 年 5 月 26 日

コメント済み:

2021 年 3 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by