필터 지우기
필터 지우기

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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by