Plotting two columns from a matrix

210 visualizaciones (últimos 30 días)
Jesus Flores
Jesus Flores el 21 de Abr. de 2021
Movida: DGM el 4 de Oct. de 2022
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];

Respuesta aceptada

DGM
DGM el 21 de Abr. de 2021
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)
  2 comentarios
Jesus Flores
Jesus Flores el 21 de Abr. de 2021
Thank you.
Seungwon
Seungwon el 4 de Oct. de 2022
Movida: DGM el 4 de Oct. de 2022
nice job

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by