Search code examples
matlab

Delete specific cell columns - Matlab


How can I generate a new cell with only column 1,2 and 8 not by merging

ca = {'Col1','Col2','Col3','Col4','Col5','Col6','Col7','Col8','Col9';
      '1', 70 , 80 , 100, 99, 99, 95, 95, 95;
      '2', 30 , 90, 95, 90, 95, 99, 95, 95;
      '3', 100, 70, 85, 90, 95, 99, 95, 95;
      '4', 100, 70, 85, 90, 95, 99, 95, 95;
      '5', 100, 70, 85, 90, 95, 99, 95, 95;
      '6', 100, 70, 85, 90, 95, 99, 95, 95;
      } 
 
partA = ca(:, 1:2)
partB = ca(:, 8)
newca = [partA,partB]

Solution

  • You can simply reference all of the columns you need in one indexing array, instead of treating columns 1/2 and 8 seperately. So

    newca = ca( :, [1,2,8] );