How to specifically select columns in a data matrix?

Hello guys,
I know this is a really simple question, which I can't seem to find any answers around on the internet or the help stuffs I've on Matlab.
I've uploaded a dataset with 100 data series. However, I'm trying to select only specific column, say column 77 to 83, and column 86. How do I do that in Matlab? Typically, it would be:
xdatatemp =xdata(:,77:86) - to select columns 77 to 86. But, how do I specifically select col 77 to 83, and col 86?
Many thanks.
J

 Respuesta aceptada

Sven
Sven el 12 de Nov. de 2011
Try:
xdatatemp = xdata(:,[77:83 86])
And you can even use "end" keywords such as:
xdatatemp = xdata(:,[77:83 86 end end:-1:end-5])
That is, of course, if you wanted columns 77 to 83, then 86, then the last column, then the last 5 columns counted backwards ;)

6 comentarios

jj
jj el 12 de Nov. de 2011
Thanks!! :)
SugerCodeCude
SugerCodeCude el 9 de Oct. de 2018
Editada: SugerCodeCude el 9 de Oct. de 2018
Sven what if there is only one row you like to pick from? for Example a 3x3 and I want only column 3 of row 3? where do you put in the code you showed to select the row too? Never mind got it! thank you
xdatatemp = xdata(:,[77:83 86])
Thank you!
This worked wonderfully, thanks! I guess there's much to learn about MATLAB syntax and functions. I'm having trouble understanding several things when compared to Python and C, where doing certain tasks are are easier than doing it in MATLAB.
Rik
Rik el 15 de Abr. de 2021
@Fernando Salamanca Guerrero, flags are not personal bookmarks, they are to alert people with editing privileges and/or staff. I have removed your flag.
Fercho_Sala
Fercho_Sala el 15 de Abr. de 2021
@Rik ok, understood... I'm sorry ;)

Iniciar sesión para comentar.

Más respuestas (2)

Coral del Mar Valle Rodriguez
Coral del Mar Valle Rodriguez el 14 de Mayo de 2020
Editada: Coral del Mar Valle Rodriguez el 14 de Mayo de 2020
I have a matrix of various rows, and three columns. some of the data sets have the same number. I would like to put them together in order to graph it. how do I separate the matrix by value? for example, all the values right to the #1, etc?
1961 1 -11.4
1961 2 -12.3
1961 3 -8.2
1961 4 -8.6
1961 5 -2.4
1961 6 7.4
1961 7 14.8
1961 8 11.1
1961 9 5.9
1961 10 3.7
1961 11 -6.3
1961 12 -13.3
1962 1 -12.7
1962 2 -8.1
1962 3 -13
1962 4 -1.1
1962 5 2.8
1962 6 5.9
1962 7 12.2
1962 8 8.9
1962 9 7.2
1962 10 -0.1
1962 11 -1
1962 12 -11

1 comentario

Rik
Rik el 20 de Ag. de 2020
Comment posted as flag by Abdul Basith Ashraf:
lookup groupsummary function. You have answered by asking a different question. Please avoid this in the future.

Iniciar sesión para comentar.

prakash patel
prakash patel el 18 de Mayo de 2020
Editada: prakash patel el 18 de Mayo de 2020

0 votos

a=[12345; 23456; 34567; 45678]
find
i (a)(2.5)
ii colom matrix v=a(;,4)
iii matrx a
iv a(:,2:3)
v sa= a(2:3, 2:4)

Categorías

Más información sobre Matrices and Arrays en Centro de ayuda y File Exchange.

Preguntada:

jj
el 12 de Nov. de 2011

Comentada:

el 15 de Abr. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by