how to plot like the following figure( i need code)

2 次查看(过去 30 天)
  2 个评论
dpb
dpb 2020-3-2
That would take only about 4-5 lines...
  1. Read the data (importdata, readtable, readmatrix, ...)
  2. plot data by column w/ X-axis column of the desired variable
  3. call xlabel(), ylabel()
  4. legend()
Give it a go...we can't do anything specific w/o knowing where the data are and in what form...
Faizullah khan
Faizullah khan 2020-3-3
The data is in the following form dear Sir
Legends will be A F M B C Proposed

请先登录,再进行评论。

采纳的回答

Andrés Castro
Andrés Castro 2020-3-2
Hi Faizullah:
You need to get the coordinates of each data, for example, in the green curve (TSMF) the data are : (5,50),(10,100),(20,250) ... so on and so forth. Remeber each point has the coordinate (x,y).
points_coords = [5 50;10 100;20 250;30 650;40 1500;50 3500]; % is a matrix of 6x2
x = points_coords(:,1); % the colon symbol in the firs potition selects every row, and the "1" the first column
y1 = points_coords(:,2);
plot(x,y1,'g-^') % the 'g-^' g = green (color) - = solid line (line type) ^ = generates triangles (marker)
TSMF_curve
As you can see is only a curve. You need to add the corresponding points within the points_coords varibale and generates new variables y2, y3 .... yn. For more information about the parameters to plot the other curves visit the plot function documentation. You can olso visit: xlabe, ylabel, title and legend commands.
Regards!
  4 个评论
Andrés Castro
Andrés Castro 2020-3-3
Yes, that's right. But now we have the data is more easier.
x = 10:10:90 % the colon operator allows define a vector on a range with increments initial:increment:final
MSE_values = [5.9392, 7.3934, 10.2113, 13.6319, 17.0441, 21.9598, 28.1901, 35.3217, 47.1861;
15.3395, 32.8796, 48.0746, 75.7206, 117.3670, 152.2416, 220.0498, 262.7240, 357.6435]
y = MSE_values'; % the ' symbol carries out the transpose of a matrix (is to say, change rows by columns and columns by rows)
hold on % hold on comand allows plot multiplecurves at the same time
grid on % grid on comand shows the grid over the plot
plot(x, y(:,1),'b-o'); % plot the A curve in color blue and marker o in a solid line
plot(x, y(:,2),'g-^'); % plot the F curve in color green and marker triangle in a solid line
legend ('A','F') % add legend at the plot
The code above produces:
x =
10 20 30 40 50 60 70 80 90
MSE_values =
5.9392 7.3934 10.2113 13.6319 17.0441 21.9598 28.1901 35.3217 47.1861
15.3395 32.8796 48.0746 75.7206 117.3670 152.2416 220.0498 262.7240 357.6435
y =
5.9392 15.3395
7.3934 32.8796
10.2113 48.0746
13.6319 75.7206
17.0441 117.3670
21.9598 152.2416
28.1901 220.0498
35.3217 262.7240
47.1861 357.6435
Now you have to add the missing values over the MSE_values matrix, then add more plot function for the other curves, for example
plot(x,y(:,3));
plot(x,y(:,4));
.
.
.
plot(x,y(:,n))
Finally change the legend comand adding the names of the missing cuvers.
Regards!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

尚未输入任何标签。

产品


版本

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by