0
$\begingroup$

I am trying to create a list list2 removing elements from a list list. The structure of list is a mix of numbers and strings, for example:

 mata = {"mc011", "mc021"};
 matb = {"mc011", "mc021"};

list=Flatten[Table[ToString[mata[[i]] <> "-" <> matb[[j]] <> "-"<> 
    ToString[Abs[eigvaltot[i, j, 0.5]]]], {i, 1, 2}, {j, 1, 2}], 1]

with the output

      {mc011-mc011-{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
       mc011-mc012-{1, 1, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.707107, 
        0.707107,0.707107, 0.707107, 0.707107, 0.707107, 0.707107, 
        0.707107},
       mc021-mc011-{1, 1, 1, 1, 1, 1, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
        0.5, 0.5, 0.5},
      mc021-mc021-{1, 1, 1, 1, 1, 1, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
        0.5, 0.5, 0.5}}

and I need to eliminate the elements that have the first $6$ numeric values $=1$, in the way

list2={mc011-mc011-{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
       mc011-mc012-{1, 1, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.707107, 
        0.707107,0.707107, 0.707107, 0.707107, 0.707107, 0.707107, 
        0.707107}}

Until now I was able to do it in a list without the strings using DeleteCases

DeleteCases[testb, {x_, y_, z_, i_, j_, k_, l_, n_, o_, p_, q_, r_, s_,
    t_, u_,v_} /; (z == 1 && i == 1 && j == 1 && k == 1 && l == 1 && 
    n == 1 && o != 1 && p != 1 && q != 1 && r != 1 && s != 1 && t != 1 && 
    u != 1 && v != 1)]

Here testb is a sample list that I made to try "DelateCases". Now the problem is that when I try to include the string it does not work

list2=DeleteCases[list, {x_, y_, {z_, i_, j_, k_, l_, n_, o_, p_, q_, r_,
      s_, t_, u_, v_, w_, a_}} /; (z == 1 && i == 1 && j == 1 && k == 1 &&
      l == 1 && n == 1)]

My list list is huge so, I need to automatize the process. Do you know a wise way to perform this procedure?. Thanks in advance.

$\endgroup$
  • 1
    $\begingroup$ In your code the mc* are symbols not string. You might need to post your raw data format which is more helpful. $\endgroup$ – L.Yu May 23 at 13:50
  • $\begingroup$ @L.Yu Thank you, I added how the list was created. The first elements are part of another list with names $\endgroup$ – mors May 23 at 14:05
  • $\begingroup$ Please make your code self-contained so that the reader can run and debug it without needing to make up missing elements like eigvaltot. Doing so will greatly increase your chances of getting usable answers. $\endgroup$ – Roman May 23 at 15:20
2
$\begingroup$

If all your data are created in Mathematica, it's easy to solve your problem by not converting everything to String but keeping the List structure:

mata = {"mc011", "mc021"};
matb = {"mc011", "mc021"};

list = Flatten[
  Table[
    {mata[[i]], matb[[j]], Abs[eigvaltot[i, j, 0.5]]},
    {i, 1, 2}, {j, 1, 2}
  ],
1];

Then to filter your list as you wish by Select:

Select[list, Count[#[[3, 1 ;; 6]], 1] != 6 &]
$\endgroup$
  • $\begingroup$ Thanks is what I needed, definitely I have to lear more $\endgroup$ – mors May 23 at 19:41
  • $\begingroup$ You are welcome! $\endgroup$ – L.Yu May 23 at 20:39

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.