Skipping numbers in lists in Mathematica

  • Context: Mathematica 
  • Thread starter Thread starter laminatedevildoll
  • Start date Start date
  • Tags Tags
    Mathematica Numbers
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 4K views
laminatedevildoll
Messages
211
Reaction score
0
Hi,

I am new to mathematica, and part of the program I have to write includes reading a file and manipulating the data for research. This file has around 22,000 numbers listed in it. I've already figured out how to look at those numbers and generate a histogram. However, what if I want to skip over numbers, meaning that now I want to read every 256th number until the end of my data set and save it each time under the same name, i.e data1, so I can generate a new histogram with these numbers. I've already tried the takedata option, without much luck.

I'd appreciate any help.
 
Physics news on Phys.org
One simple way to do it would be to write a For [ ] - loop over your data with the appropriate incrementation and writing the operation (the save) in the body of the for-statement.
 
Okay, I figured out how to skip numbers by using a Do loop.

Here's my code so far...

data = BinaryReadList[file,"Integer16"]
lngth = Length[data]
stepsize = 255
numiter = IntegerPart[lngth/stepsize]
initobs=1
data1={}
Do[data1=Append[data1,data[[i]]], {i,initobs,numiter*stepsize,stepsize}]
Readlist[data1]

However, I need to evaluate this 256 times where initobs = 1,2...256. I tried to put this whole expression in a do loop, so that it could output 256 different list for different values of initobs, but it doesn't work. What am I doing wrong?