As mentioned in the comments to your question, you just Import
the whole data and then manipulate it afterwards. This is (I believe) a very transparent way to achieve the end result that you want and also illustrates why you should not use an "advanced" Import
:
Let's produce some sample data
dim = 100;
data = RandomReal[{-1, 1}, {dim, 3}];
Export[NotebookDirectory[] <> "dummy.dat", data, "Table"];
ClearAll[data];
of which we want to exclude certain rows:
exclude = RandomInteger[{1, dim}, 8];
wanted = DeleteCases[Range[dim], Alternatives @@ exclude];
Of course, if you do just Import
your data, say into the variable import
, then dim=First@Dimensions@import
. Now let's compare the two approaches:
Import everything and manipulate afterwards:
First@AbsoluteTiming[
data = Import[NotebookDirectory[] <> "dummy.dat", "Table"];
correctedData = data[[wanted]];]
(* 0.023810 *)
Import only the wanted rows:
First@AbsoluteTiming[correctedImport = Import[NotebookDirectory[] <> "dummy.dat", {"Data", wanted}];]
(* 0.050041 *)
Note that the latter uses the built-in functionality of Import
Import["file",elements]
: imports the specified elements from a file.
Now, we verify that both are the same:
correctedData == correctedImport
(* True *)
So, concluding, it is probably only useful to import specified elements if you would run into memory issues otherwise. If there are no limitations due to ressources, importing everything and manipulating afterwards is faster.
Import
has nothing to do with your approch, as youImport
the whole file and then take aPart
of it... take a look atPart
,Span
andDrop
which will come in very handy for such tasks. $\endgroup$ – Yves Klett Apr 8 '16 at 11:26N,E,D,...
.N
- which you used - is already defined. $\endgroup$ – Lukas Apr 8 '16 at 11:39myVariableName
,myFun[x]:=...
. For one letters variables, just use the uncapitalized version. $\endgroup$ – Lukas Apr 8 '16 at 12:47