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

  • SEARCH
  • Home
  • 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 708529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:24:04+00:00 2026-05-14T04:24:04+00:00

I have a database table full of time points and experimental values at those

  • 0

I have a database table full of time points and experimental values at those time points. I need to retrieve the values for an experiment and create a thumbnail image showing an XY plot of its data. Because the actual data set for each experiment is potentially 100,000 data points and my image is only 100 pixels wide, I want to sample the data by taking every nth time point for my image and ignoring the rest.

My current query (which retrieves all the data without sampling) is something simple like this:

var points = from p in db.DataPoints
             where p.ExperimentId == myExperimentId
             orderby p.Time
             select new {
                            X = p.Time,
                            Y = p.Value
                        }

So, how can I best take every nth point from my result set in a LINQ to SQL query?

  • 1 1 Answer
  • 2 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-05-14T04:24:04+00:00Added an answer on May 14, 2026 at 4:24 am

    This will do every nth element:

    int nth = 100;
    var points = db.DataPoints
               .Where(p => p.ExperimentId == myExperimentId)
               .OrderBy(p => p.Time)
               .Where( (p, index) => index % nth == 0 )
               .Select( p => new { X = p.Time, Y = p.Value } );
    

    It works by using the Queryable.Where overload which provides an index in the sequence, so you can filter based off the index.

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

Sidebar

Related Questions

I have a database table which is full-text indexed and i use the CONTAINS-function
I have a database table named Categories . I want to create a form
I have a database table with 5 rows. The first time I do a
I have a database table that is full of transactions transactionIDs and datetime fields.
I have a database full of time-sensitive data, so on a daily basis I
I have a SQL Server database running in Full recovery. I need to remove
i have database table like this +-------+--------------+----------+ | id | ip | date |
that my problem: I have database table like that: id (AI) market_id 1 6
I have a database table with some rows that I want to fetch using
I have a database table containing dates (`date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00').

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.