Truncating rows from a matrix

2 次查看(过去 30 天)
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

采纳的回答

Mischa Kim
Mischa Kim 2014-4-30
编辑:Mischa Kim 2014-4-30
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 个评论
Mohammad Sayeed
Mohammad Sayeed 2014-4-30
It worked with my data set. Thank you very much Mischa, for your great contribution.
Kind regards
Sayeed

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by