0

I have set of files say 1 to 10. Each of these files have 3 subsets like 1-0,1-1,1-2; 2-0,2-1,2-2; and so on. i.e total 30 files in all. I am using the following code to extract the information from all 0th subset:

files = Range[1, 10]; 
path = "D:\\20180126-";
a = Length[files];

c = path <> ToString[#] <> "-0.txt" & /@ files; 
d = Table[Import[c[[i]], "Table"], {i, 1, a}]; 

mns[d_] =  Module[{ma}, 
  ma = Table[{
    Total[d[[i]][[1000 ;; 2000]]], 
    Total[d[[i]][[2000 ;; 2500]]]}
  , {i, 1, Length[d]}] /. {x_} :> x
]

e = mns[d]

so far so good. But when I am trying to extract the same information from subsets "1" and "2" using the following code, I am getting the same values as obtained for 0th subset.

c = path <> ToString[#] <> "-1.txt" & /@ files;
e = mns[d]

c = path <> ToString[#] <> "-2.txt" & /@ files;
e = mns[d]

Thanks in advance

Kuba
  • 136,707
  • 13
  • 279
  • 740
surjendu
  • 45
  • 3
  • Here I have another solution which provides me the same result but in a different approach. files = Range[4, 20]; path = "D:\20180126-"; a = Length[files]; For[i = 0; c = x, i < 3, i++, c = path <> ToString[#] <> "-" <> ToString[i] <> ".txt" & /@ files; d = Table[Import[c[[i]], "Table"], {i, 1, a}]; e = Table[{Total[d[[i]][[1000 ;; 2000]]], Total[d[[i]][[2000 ;; 2500]]]}, {i, 1, Length[d]}] /. {x_} :> x; Print[e]; ] – surjendu Jan 27 '18 at 16:36
  • What if you use: mns[d_]:=...? Please lookup Set and SetDelayed. See linked topic, especially: Understand the difference between Set (or =) and SetDelayed (or :=) – Kuba Apr 09 '18 at 12:31

0 Answers0