How should I draw a line?

6 次查看(过去 30 天)
JooYoung Jeon
JooYoung Jeon 2021-11-29
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 个评论
DGM
DGM 2021-11-29
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 2021-11-29
I want to draw a line in this way so that it can move along the drawn plot.

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2021-11-29
编辑:Image Analyst 2021-11-29
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 个评论
DGM
DGM 2021-11-30
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 2021-11-30
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by