New answers tagged

2

I found the problem is with my original data; there are some unexpected Line Feed characters in my data which were causing me to misinterpret the result of "Import" using type CSV. The comments by Yode and JasonB prompted me to look at the file with notepad++ so I could see the LF characters. Sorry for the confusion.


2

Import takes all sheets, which nests the data. First@ takes the first sheet formatting the data you need for the subsequent expressions. test = First@Import["Velocidade Angular.xls"]; time = test[[All, 1]]; x = test[[All, 2]]; f = Interpolation[Transpose[{time, x}], InterpolationOrder -> 3]; Show[ ListPlot[test[[All, 1 ;; 2]], PlotStyle -> Red], ...


0

There is another solution, different from the one posted by @Szabolcs. It deals with string replacing and then converting to expression: readMatlabComplex[file_] :=ToExpression[ StringSplit[ StringReplace[ ReadList[file, "String"] , {"e" -> "*10^", "i" -> "*I"}] , ","]] It is about 10 times faster.


5

Here's a solution using your example file. Import as RawJSON because this gives us much easier to manipulate associations. json = Import[ "https://raw.githubusercontent.com/d3/d3-plugins/master/graph/data/miserables.json", "RawJSON"] After inspecting the format manually, it's easy to extract vertices: vertices = json[["nodes", All, "name"]] Links ...


2

SemanticImport will handle it. Specify the column types explicitly. Example with one column: SemanticImportString[ "-5.07248931892817e-05+2.50260543778902e-18i -5.0723848172051e-05+2.870855441657444e-17i", {"ComplexNumber"} ] This returns a Dataset which you can convert to a list using Normal. Update: I can import your file without problems in ...


4

Import and ImportString handle the e number format okay. You might be able to Import directly from file, or use ImportString to process the data you've already read in: res = fromReadList ~StringRiffle~ "\n" ~ImportString~ "TSV" ~Cases~ {__,"Cake"|"Cookies",_};


10

I would like to link this W Community thread here where I asked for functionality like this in 2015 September, and explained why it's critical to have it. I can't link to individual posts but you can find it by searching the page for "StringToDouble". As Leonid mentioned, there is Internal`StringToDouble. This function is very fast, but it does not ...


1

The problem here stems from the filenames being in alphabetical order. If you separate the numbers from the ".txt" suffix with StringSplit, you can use ToExpression to get Mathematica to treat them as numbers and put them in numerical order. Then use Ordering to put the original list of filenames in the same order as the list of numbers. filelist = {"1.dat"...


1

Szabolcs Horvát has a great bit of code that makes bring in tabular data via copy and paste super easy: Pasting tabular data from the web http://szhorvat.net/pelican/pasting-tabular-data-from-the-web.html


0

I cut and paste the numbers you have to a .csv file, importing them and was left with the numbers in Text format. Try this. ToExpression[Flatten[StringSplit[Flatten[Import["C:\\File.csv"]]]]] It flattens and converts it to a expression, numbers instead of text format.


4

Make some sample data consisting of numbers and spaces: samepleData = Module[{seed = ToString@Table[RandomInteger[{0, 10000}], 50]}, StringReplace[seed, {"{" -> " ", "}" -> " ", "," -> RandomChoice[{" ", " ", " "}]}]] (* 7476 8829 1505 3337 7282 7244 ...


2

Number counting approach Since your file contains (with rare exceptions) only 3 numbers on each line and the data has dimensions {400,4001,2}, it is possible to calculate how many lines you should read in order to obtain the first 40 sets out of 400. At first, some checks: data = << "EigF-V1_1.0-V2_0.000.txt"; Dimensions[data] {400, 4001, 2} ...



Top 50 recent answers are included