필터 지우기
필터 지우기

Select multiple ranges from a column and insert these into new column

조회 수: 5 (최근 30일)
Laura Albers
Laura Albers 2018년 4월 11일
답변: Ameer Hamza 2018년 4월 21일
Hello!
I imported a full (38529x1) column containing Socio Economic Acocunts for 2014 into Matlab. However, I only want to take out certain ranges and insert them into a new column which will be called EMPE_2014. So the first range I want to extract from the full column ranges from 170:225, the second from 1066:1121 etc. Every range consists of 56 variables, and the difference between the ranges is the same as between the first and second I gave here above.
Does someone know how to create a new column containing 43 ranges, each range containing 56 variables? Thank you in advance

답변 (1개)

Ameer Hamza
Ameer Hamza 2018년 4월 21일

It can be done as follow,

  • Generate the required indexes
interval = 55;
difference = 1066-170;
ind = [];
current_ind = 170;
while current_ind+difference<38529
  ind = [ind current_ind:current_ind+interval];
  current_ind = current_ind+difference;
end
  • Extract required values from the old vector
new_vector = old_vector(ind);

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by