Plotting two columns from a matrix

184 次查看(过去 30 天)
Can someone please help me. I need to plot a line graph with the second column being on the x-axis and fourth column on the y-axis from the following matrix. Thank you.
nick_data =[
3 1994 NaN 1592
3 1995 NaN 1562
3 1997 NaN 1539
4 1993 NaN 1514
4 1996 NaN 1498
4 1998 NaN 1408
4 1999 NaN 1319
5 1992 NaN 1538
5 2000 NaN 1211
5 2001 NaN 1155
6 1990 NaN 1579
6 2002 NaN 1035
7 1989 NaN 1599
7 1991 NaN 1502
10 2003 NaN 974
10 2004 NaN 916
13 1985 NaN 1337
13 1986 NaN 1312
13 1987 NaN 1284
13 2005 NaN 827
13 2006 NaN 778
14 1980 NaN 1329
14 1981 NaN 1300
16 1984 NaN 1282
16 2007 NaN 651
19 1982 NaN 1131
19 1983 NaN 1114
21 2008 NaN 592];

采纳的回答

DGM
DGM 2021-4-21
nick_data =[
3 1994 NaN 1592
3 1995 NaN 1562
3 1997 NaN 1539
4 1993 NaN 1514
4 1996 NaN 1498
4 1998 NaN 1408
4 1999 NaN 1319
5 1992 NaN 1538
5 2000 NaN 1211
5 2001 NaN 1155
6 1990 NaN 1579
6 2002 NaN 1035
7 1989 NaN 1599
7 1991 NaN 1502
10 2003 NaN 974
10 2004 NaN 916
13 1985 NaN 1337
13 1986 NaN 1312
13 1987 NaN 1284
13 2005 NaN 827
13 2006 NaN 778
14 1980 NaN 1329
14 1981 NaN 1300
16 1984 NaN 1282
16 2007 NaN 651
19 1982 NaN 1131
19 1983 NaN 1114
21 2008 NaN 592];
% well you can plot it if you want, but it's not sorted
plot(nick_data(:,2),nick_data(:,4))
% maybe you want to sort it?
[sortedx idx]=sort(nick_data(:,2));
sortedy=nick_data(:,4);
sortedy=sortedy(idx);
plot(sortedx,sortedy)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by