Filter löschen
Filter löschen

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

2 Ansichten (letzte 30 Tage)
Faizullah khan
Faizullah khan am 2 Mär. 2020
Kommentiert: Faizullah khan am 5 Mär. 2020
  2 Kommentare
dpb
dpb am 2 Mär. 2020
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 am 3 Mär. 2020
The data is in the following form dear Sir
Legends will be A F M B C Proposed

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Andrés Castro
Andrés Castro am 2 Mär. 2020
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 Kommentare
Andrés Castro
Andrés Castro am 3 Mär. 2020
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 am 5 Mär. 2020
Thank you very much Andrés Castro Sir .

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Noch keine Tags eingegeben.

Produkte


Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by