Skipping numbers in lists in Mathematica

  • Context: Mathematica 
  • Thread starter Thread starter laminatedevildoll
  • Start date Start date
  • Tags Tags
    Mathematica Numbers
Click For Summary
SUMMARY

The discussion focuses on manipulating data in Mathematica by skipping numbers in a list. The user successfully generates a histogram from a dataset containing 22,000 integers but seeks to extract every 256th number for further analysis. They initially attempted to use the `takedata` option and a `For` loop but found success with a `Do` loop. The provided code effectively appends every 256th number to a new list, but the user struggles to iterate this process for different initial observations (initobs) to create multiple lists.

PREREQUISITES
  • Familiarity with Mathematica programming language
  • Understanding of list manipulation techniques in Mathematica
  • Knowledge of control structures such as loops in Mathematica
  • Basic data analysis concepts, particularly histogram generation
NEXT STEPS
  • Learn about advanced list manipulation functions in Mathematica
  • Explore the use of `Table` for generating multiple lists efficiently
  • Investigate the `BinaryReadList` function for reading large datasets
  • Study the `Append` function and its performance implications in Mathematica
USEFUL FOR

Data analysts, researchers, and Mathematica users who need to manipulate large datasets and generate histograms from selective data points.

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?
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 22 ·
Replies
22
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 4 ·
Replies
4
Views
7K