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 6535939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:25:56+00:00 2026-05-25T10:25:56+00:00

This is a small thing but has been bothering me for a while now,

  • 0

This is a small thing but has been bothering me for a while now, so I thought I would let the crowd solving begin 🙂

I have a matrix with timestamps and a corresponding logical value (or 1/0), i.e.

of = [-inf 0 10 15 190 inf; 1 0 0 1 1 0]'

and an another time vector, e.g.

t = 0:0.1:1e3;

or whatever, you get the point 🙂

Now how do I (read: would you) inter-/extrapolate the logical infomation in of so it matches the timestamps in t, but with the interpolated logicals always assuming the last or current value, not a future one?

Don’t know if that makes sense, but here is the expected output given of and t2

t2 = [0 5 14 16]
output = [0 0 10 15; 0 0 0 1]'

where the first column of output is the time of of used in interpolation. If I use interp1 and the ‘nearest’ algorithm, it will give

interp1(of(:,1), of, t2, 'nearest')
output = [0 10 15 15; 0 0 1 1]'  

which is not exactly what I want.

  • 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-05-25T10:25:56+00:00Added an answer on May 25, 2026 at 10:25 am

    Assuming your vectors are sorted you could try that, which seems to work with your example although I did not tested it extensively:

    of=[-inf 0 10 15 190 inf; 1 0 0 1 1 0]';
    t2 = [0 5 14 16];
    index=floor(interp1(of(:,1),(1:size(of,1))',t2'));
    output=of(index,:);
    

    Hope it helps.

    The default method used by interp1 is linear, which works best with your condition because you do not want the “nearest” neighbor but the first lower or equal neighbor (as far as I understand this). Therefore a simple truncation of the interpolated timestamps index gives you the result.

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

Sidebar

Related Questions

How are things now This has been discussed in many questions but neither one
So, I know this has been done to death but all the answers I've
This question has been asked here in one form or another but not quite
I know this type of question has been asked before, but I could not
We use this small utility method. But we don't like it. Since it's not
This has been driving me mad for the past hour and a half. I
Well, I guess this day had to come. My client's website has been compromised
Quick question. I have been Googling this all morning, but it's either not there,
I've got this small question - given a bitmask of weekdays (e.g., Sunday =
I have this small code library that I'm considering releasing into Open Source. I

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.