1
$\begingroup$

I have a nested matrix n:

n = {{a, b}, {c, d}}
a = {{0, t, q, dh}, {0, 1, 0, th}, {1, 0, 0, sh}}
b = {{0, t, q, dh}, {0, 0, 0, th}, {0, 0, 1, sh}}

c = {{0, t, q, dh}, {1, 0, 1, th}, {0, 0, 0, sh}}
d = {{0, t, q, dh}, {0, 1, 0, th}, {1, 0, 0, sh}}

With thanks to Kuba and Mr.Wizard 'comparison-operation-for-nested-matrices' I could get a combined nested matrix: ncombined (on which a comparison operation was applied)

ncombined= {{
   {{0, t, q, dh}, 
    {0, 1, 0, th}, 
    {1, 0, 1, sh}}},
   {{{0, t, q, dh}, 
    {1, 1, 1, th}, 
    {1, 0, 0, sh}}
           }}

and with thanks to Kgular getting-good-looking-matrix..I could add a vector m as:

m = {rr, kk}

to the ncombined as bellow:

pp = Transpose[Insert[Transpose[ncombined], Flatten@m, 1]];
ppgoodlook=MapAt[MatrixForm, pp, {{All, All}, {}}]

enter image description here

I am so sorry if my question maybe will not well written while I have so much tried to write it more obviously. Also I will bring the image of the desired result.

question: Since, number 1 is not repeated in the same elements of a and b , also for c and d, how can I refer each of 1 in the ppgoodlook to the main sub_matrices such as a, b, c or d (from which, 1 is gone to ppgoodlook) in order to obtain the bellow result (However this referring is regardless to the letters of sub_matrices such as sh,th, q, t and dh) :

enter image description here

$\endgroup$
1
$\begingroup$
ncombined = {{{{0, t, q, dh}, {0, 1, 0, th}, {1, 0, 1, sh}}},
              {{{0, t, q, dh}, {1, 1, 1, th}, {1, 0, 0, sh}}}};
pos = Join @@ (Thread[{Position[#1, 1], #2}] & @@@ 
     Thread[{{a, b, c, d}, {"a", "b", "c", "d"}}]);
pos = pos /. {{{x_, y_}, p : "a" | "b"} :> {{1, 1, x, y},  p}, 
              {{x_, y_}, p : "c" | "d"} :> {{2, 1, x, y}, p}};
ncombined2 = ncombined;
(ncombined2[[Sequence @@ #[[1]]]] = #[[2]]) & /@ pos;
m = {rr, kk};
pp2 = Transpose[Insert[Transpose[ncombined2], Flatten@m, 1]];
ppgoodlook2 = MapAt[MatrixForm, pp2, {{All, All}, {}}]

enter image description here

$\endgroup$
  • $\begingroup$ Thanks a bunch for your answer, Should you extend your answer to a general problem. I mean if we do not know the exact palace of 'a' and 'b' also, 'c' and 'd'. you separated, a and b, c and d in the line: pos = pos /. {{{x_, y_}, p : "a" | "b"} :> {{1, 1, x, y}, p}, {{x_, y_}, p : "c" | "d"} :> {{2, 1, x, y}, p}}; But if we have d in the topmost sub_matrices near the a and b, what must we do? $\endgroup$ – Unbelievable Jul 1 '14 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.