Truncating rows from a matrix

2 ビュー (過去 30 日間)
Mohammad Sayeed
Mohammad Sayeed 2014 年 4 月 30 日
コメント済み: Mohammad Sayeed 2014 年 4 月 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 Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by