Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9192361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:54:10+00:00 2026-06-17T20:54:10+00:00

I’m currently working on handling some experimental data with Mathematica. I have several files

  • 0

I’m currently working on handling some experimental data with Mathematica.

I have several files that I basically want to do the same thing with. At the moment, I just copy and paste everything and change the filenames, which looks like this:

rechn1 = Import[
   "/path/4He.H2O.MeV14460.ddd.gd.dat", "Table"];
r1 = Length[rechn1];
rechn1a = Take[rechn1, {9, r1}];
plotr1 = ListPlot[rechn1a]

rechn2 = Import[
   "/path/4He.H2O.MeV15000.ddd.gd.dat", "Table"];
r2 = Length[rechn2];
rechn2a = Take[rechn2, {9, r2}];
plotr2 = ListPlot[rechn2a]

rechn3 = Import[
   "/path/4He.H2O.MeV15670.ddd.gd.dat", "Table"];
r3 = Length[rechn3];
rechn3a = Take[rechn3, {9, r3}];
plotr3 = ListPlot[rechn3a]

and so on.
I’m not especially well versed in Mathematica, so this to me seemed like a good option. Copy, paste, change a few numbers.

However, I now have to handle even more data like this. So, is there any way to tell Mathematica to handle all files a certain way? And maybe also to change just a few details? For example, handle everything the same, but have a different PlotStyle or title for the plots?

It would be great to find a way to automate this process a bit, since I have a lot of files to handle now and copy and pasting just isn’t an option any more.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:54:11+00:00Added an answer on June 17, 2026 at 8:54 pm

    As usual with Mathematica there is a variety of ways to do what you want. Here are some pieces you may be able to assemble into a solution which works for you.

    You could replace your sequence of 4 function invocations with a composition of them all, like this:

    ListPlot[Drop[Import["/path/4He.H2O.MeV15670.ddd.gd.dat", "Table"], 9]]
    

    This is initially a lot harder to interpret (for you, Mathematica won’t have a problem) but it will be easier to use in what follows, and it will avoid cluttering up your workspace with unnecessary temporary variables. Note that I’ve replaced your Take[expr,{9,Length[expr]}] with the equivalent Drop[expr,8] to avoid having to call Length on the imported data file.

    Now we can tidy this up into a function, such as:

    makePlot[fn_String] := ListPlot[Drop[Import[fn, "Table"], 8]]
    

    Next, lets get all the filenames you need. I suppose that your current working directory is the parent of “/path” and that the call

    hefiles = FileNames["4He.*.ddd.gd.dat", {"*"}, Infinity];
    

    will return a list of the names of all your input files. Let’s modify the makePlot function for reasons which will become obvious in a moment:

    makePlot[ix_Integer, fn_String] := myPlots[ix] = ListPlot[Drop[Import[fn, "Table"], 9]];
    

    Now, you can write

    Do[makePlot[i,heFiles[[i]]],{i,1,Length[heFiles}]
    

    and this ought, if I’ve got the syntax right and matched up all the brackets, to make all your plots with one statement. They will now be stored as myPlots[1], myPlots[2], ....

    If you want to set options for your ListPlot command simply amend the definition of makePlot to something like

    makePlot[fn_String] := ListPlot[Drop[Import[fn, "Table"], 8],plotOption-> setting, plotOption2->setting2]
    

    or, if you want to make leaps and bounds in your Mathematica knowledge, investigate the Options function and you can modify makePlot to take options as (optional) arguments and pass them through to ListPlot.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I have just tried to save a simple *.rtf file with some websites and
I have a small JavaScript validation script that validates inputs based on Regex. I
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I want to construct a data frame in an Rcpp function, but when I
I have thousands of HTML files to process using Groovy/Java and I need to
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.