Borrar filtros
Borrar filtros

Truncating rows from a matrix

2 visualizaciones (últimos 30 días)
Mohammad Sayeed
Mohammad Sayeed el 30 de Abr. de 2014
Comentada: Mohammad Sayeed el 30 de Abr. de 2014
I have a matrix of panel data with 23 cross sections and 144 time intervals. So total number of rows is 23*144=3312 in the matrix with 10 columns for ten variables. I need to get rid of few data from each of the cross sections. such as I want to discard 10th, 15th, 20th, 90th and 120th time-interval data from each each cross section so that I will have a matrix of 23*139=3197 rows. How can do it in MATLAB? Can anyone help?
Kind regards
Sayeed

Respuesta aceptada

Mischa Kim
Mischa Kim el 30 de Abr. de 2014
Editada: Mischa Kim el 30 de Abr. de 2014
Mohammad, not knowing exactly how your data is organized you could follow this path:
data = eye(12); % as an example I use a 12-by-12 unity matrix
dataC = cell2mat(mat2cell(data,4*ones(1,3),12).');
dataC([2 3],:) = []; % replace [2 3] by [10 15 20 90 120]
dataR = cell2mat(mat2cell(dataC,2,12*ones(1,3)).');
Using the mat2cell command, first reshape the matrix from a 23*144-by-10 to a 144-by-23*10. Eliminate the rows and convert back to a 23*139-by-10. In other words try
dataC = cell2mat(mat2cell(data,144*ones(1,23),10).');
dataC([10 15 20 90 120],:) = [];
dataR = cell2mat(mat2cell(dataC,139,10*ones(1,23)).');
  1 comentario
Mohammad Sayeed
Mohammad Sayeed el 30 de Abr. de 2014
It worked with my data set. Thank you very much Mischa, for your great contribution.
Kind regards
Sayeed

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by