how use plotxy() command?

I want to plot x vs y. for example:(x={3,2,4,5,6}) . and y={3,5,1,6,7}.

Now draw plot by plotxy(x,y). I think the plot has not drawn correctly. data on the X axis is not ascending order. I think gauss gives a number for each element in matrix x respectively. like( 3=1, 2=2, 4=3, 5=4, 6=5) and then plot x=1,2,3,4,5 vs Y. how can plot x vs y.

3 Answers



0



accepted

Actually, in this case, GAUSS plots the points exactly as you pass them in. However, since some of the lines overlap, it is hard to tell. In this case, GAUSS draws the following line segments in this order:

1. x = 3, y = 3
2. x = 2, y = 5
3. x = 4, y = 1
4. x = 5, y = 6
5 x = 6, y = 7

Since GAUSS will draw exactly what you ask it to plot, if you want GAUSS to draw the plot in a particular order, that is the order in which you need to pass the inputs. So, if you want to see:

1. x = 2, y = 5
2. x = 3, y = 3
3. x = 4, y = 1
4. x = 5, y = 6
5. x = 6, y = 7

Then you can do this:

//Create data as described
x={ 3, 2, 4, 5, 6 };
y={ 3, 5, 1, 6, 7};

//Find index that will sort 'x' in increasing order
idx = sortind(x);

//Reorder index to 'x' and 'y'
x = x[idx];
y = y[idx];

//Plot sorted data
plotXY(x, y);

aptech

1,773


0



thank you so much

but I think we should change y=x[idx] to y=y[idx], is not it?



0



Yes, you are correct to point out the silly mistake in the answer. I will fix the mistake in the answer.

aptech

1,773

Your Answer

3 Answers

0
accepted

Actually, in this case, GAUSS plots the points exactly as you pass them in. However, since some of the lines overlap, it is hard to tell. In this case, GAUSS draws the following line segments in this order:

1. x = 3, y = 3
2. x = 2, y = 5
3. x = 4, y = 1
4. x = 5, y = 6
5 x = 6, y = 7

Since GAUSS will draw exactly what you ask it to plot, if you want GAUSS to draw the plot in a particular order, that is the order in which you need to pass the inputs. So, if you want to see:

1. x = 2, y = 5
2. x = 3, y = 3
3. x = 4, y = 1
4. x = 5, y = 6
5. x = 6, y = 7

Then you can do this:

//Create data as described
x={ 3, 2, 4, 5, 6 };
y={ 3, 5, 1, 6, 7};

//Find index that will sort 'x' in increasing order
idx = sortind(x);

//Reorder index to 'x' and 'y'
x = x[idx];
y = y[idx];

//Plot sorted data
plotXY(x, y);

0

thank you so much

but I think we should change y=x[idx] to y=y[idx], is not it?

0

Yes, you are correct to point out the silly mistake in the answer. I will fix the mistake in the answer.


You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.