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

1 view (last 30 days)
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

Answers (1)

Ameer Hamza
Ameer Hamza on 21 Apr 2018

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);

Categories

Find more on Language Fundamentals in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!