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

조회 수: 1 (최근 30일)
Faizullah khan
Faizullah khan 2020년 3월 2일
댓글: Faizullah khan 2020년 3월 5일
  댓글 수: 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!
Faizullah khan
Faizullah khan 2020년 3월 5일
Thank you very much Andrés Castro Sir .

댓글을 달려면 로그인하십시오.

추가 답변 (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