How should I draw a line?

2 vues (au cours des 30 derniers jours)
JooYoung Jeon
JooYoung Jeon le 29 Nov 2021
Commenté : Image Analyst le 30 Nov 2021
In the picture below, I would like to draw a line that goes to the left by connecting blue, red, yellow, and purple to the vertical line. What should I do?
  2 commentaires
DGM
DGM le 29 Nov 2021
I'm not sure what you mean. Do you want to create a vertical line somewhere and then extrapolate each of those series such that they meet it? Where should the vertical line be?
It might help to sketch out what you want.
JooYoung Jeon
JooYoung Jeon le 29 Nov 2021
I want to draw a line in this way so that it can move along the drawn plot.

Connectez-vous pour commenter.

Réponses (1)

Image Analyst
Image Analyst le 29 Nov 2021
Modifié(e) : Image Analyst le 29 Nov 2021
Try getting the left most point of each array and then using plot. Untested code (because you forgot to attach your data):yLeft
% Get the x values of the left most point on the colored lines, and their indexes.
[minxBlue, indexBlue] = min(xBlue);
[minxRed, indexRed] = min(xRed); % Orange, really
[minxYellow, indexYellow] = min(xYellow);
[minxPurple, indexPurple] = min(xPurple);
% Using the index, get the corresponding y value for the leftmost point.
yLeftBlue = yBlue(indexBlue);
yLeftRed = yRed(indexRed);
yLeftYellow = yYellow(indexYellow);
yLeftPurple = yPurple(indexPurple);
% Construct the red line coordinates.
xLeft = [minxBlue, minxRed, minxYellow, minxPurple]
yLeft = [yLeftBlue, yLeftRed, yLeftYellow, yLeftPurple]
% Plot the line between the leftmost points of the 4 colored lines.
plot(xLeft, yLeft, 'r-', 'LineWidth', 7);
Replace variable names to match what you have in your program for the various colored lines.
  3 commentaires
DGM
DGM le 30 Nov 2021
The second output argument of min() is the index where the minimum value was located. For the line
[minxBlue, indexBlue] = min(xBlue);
The minxBlue value is the global minimum of the vector xBlue, and it is found at xBlue(indexBlue).
The idea is to find the leftmost values in the xdata for each series, then use that associated index to find the corresponding values in the ydata for each series. This will give you a set of four points (coordinate pairs), one at the leftmost end of each of the curves. The rest is simply taking those four points and plotting a polyline between them.
Image Analyst
Image Analyst le 30 Nov 2021
Yes, thanks @DGM for explaining. The reason I did it this way instead of just using the very first element of the colored x and y is that the very first element is not guaranteed to be the left most data point. It's possible that the first element could be on the right instead of the left. We can't assume that element #1 is the left-most. That's why, to be most general, it had to be done this way.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Scatter Plots dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by