matlab - Construct matrix according to the arrangement in another matrix -


i have matrix 'eff_tot' dimension (m x n) want rearrange according matrix called 'matches' (e.g. [n2 n3; n4 n5]) , put collumns not specified in 'matches' @ end.

that is, want have [eff_tot(:,n2) eff_tot(:,n3) ; eff_tot(:,n4) eff_tot(:,n5) ; eff_tot(:,n1)].

that's folks!

taking example in first answer, have is:

eff_tot =

81    15    45    15    24 44    86    11    14    42 92    63    97    87     5 19    36     1    58    91 27    52    78    55    95 82    41     0     0     0 87     8     0     0     0  9    24     0     0     0 40    13     0     0     0 26    19     0     0     0 

regards.

create vector listing indices of columns in eff_tot , use setdiff determine columns not occur in [n2 n3 n4 n5]. these columns unmatched ones. concatenate matched , unmatched column indices create column-reordered eff_tot matrix.

 >> eff_tot = randi(100, 5, 7)  eff_tot =      45    82    81    15    15    41    24     11    87    44    14    86     8    42     97     9    92    87    63    24     5      1    40    19    58    36    13    91     78    26    27    55    52    19    95  >> n2 = 3; n3 = 5; n4 = 2; n5 = 6; >> missingcolumn = setdiff(1:size(eff_tot, 2), [n2 n3 n4 n5])  missingcolumn =       1     4     7  >> eff_tot = [eff_tot(:,n2) eff_tot(:,n3) eff_tot(:,missingindex); eff_tot(:,n4) eff_tot(:,n5) zeros(size(eff_tot, 1), length(missingindex))];  eff_tot =      81    15    45    15    24     44    86    11    14    42     92    63    97    87     5     19    36     1    58    91     27    52    78    55    95     82    41     0     0     0     87     8     0     0     0      9    24     0     0     0     40    13     0     0     0     26    19     0     0     0 

Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -