hierarchy code in matlab