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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:58:42+00:00 2026-06-17T17:58:42+00:00

Background I have 4 data sets: one is weather data with time and pressure

  • 0

Background

I have 4 data sets: one is weather data with time and pressure and another is a pressure sensor data set with the same; time and pressure. Essentially, both are a time series. The longer time series is the weather data which has about 64008 data points for both variables. The shorter time series for the pressure sensors is 51759. You could say that the shorter time series is a subset of the longer time series with some missing data points. Regardless, I want to get pressure for the weather but only for the times that my sensor has.

Motivation

So basically, I am trying to implement a while loop so that for every equivalent time pf my pressure sensor, and whether data, I will take the pressure from the weather data. I don’t need to record time from the weather data because I can just use the time sequence from my pressure sensor.

Example

To a get an idea of what I am talking about, I did a sample script and it runs just fine.

x(:,1) = (1:50)';
x(:,2) = (51:100)';
y(:,1) = [1:12 20:25 40:45]';

i = 1;
j = 1;
while i < numel(y)+1
     if y(i) == x(j,1)
        a(i,1) = x(j,2);
        i = i + 1;
        j = j + 1;
     else 
        j = j + 1;    
    end
end

a
% check
size(y)
size(a)

As you can see, I made a vector of x with a long series in 2 columns. And then I made a subset of values of vector y which includes data points that are contained in the x vectors. I run my script, the size of a matches y which means that the size comes out to be the same. I also saw that the matrix itself had the same values. So it works. Unless this is a simplified version where I’m missing something. Either way, my real script is below.

% Pressure Data
west_time;
west_pressure;
% Weather Data
weather_data(:,1) = weather_time;
weather_data(:,2) = weather_pressure;
% Initialize vector
weather_pressure_sensor = zeros(numel(west_time));

% Obtaining the pressure from the weather data at a 
% particular point in time when it corresponds 
% with the time from my pressure sensor
i = 1;
j = 1;
while i < numel(west_time),
   if west_time(i) == weather_data(j,1)
       weather_pressure_sensor(i,:) = weather_data(j,2);
       i = i + 1;
       j = j + 1;
   else 
       i = i;
       j = j + 1;
   end  
end

% Weather Pressure
weather_pressure_final = weather_pressure_sensor(:,2);

However, when i go to my data set, I run into an error code:

Attempted to access weather_data(64009,1); index out of
bounds because size(weather_data)=[64008,2].

Error in data_timeset2 (line 69)
    if west_time(i) == weather_data(j,1)

I was wondering if I could get some assistance with my code. Am I missing something or did I not define something? This is the way I’ve always done while loops so I don’t know why it decides to fail me now. But in any case, I’m sure it’s something really trivial and stupid but I can’t figure out for the life of me. Or maybe someone has another way…? Either way, much appreciated in advance!

  • 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-17T17:58:44+00:00Added an answer on June 17, 2026 at 5:58 pm

    If the time points in your data set are unique, there is a much better way to do this.

    t1 = [...]; #% time series 1
    t2 = [...]; #% time series 2; is a subset of t1
    p1 = [...]; #% pressure series 1; same length as t1
    p2 = [...]; #% pressure series 2; same length as t2
    
    [t1, index] = sort(t1); #% make monotonic if it isn't already
    p1 = p1(index); #% apply same sorting to pressures
    [t2, index] = sort(t2); #% same for t2, p2
    p2 = p2(index);
    
    [Lia, Locb] = ismember(t2, t1); #% Lia contains indices of t2 that are in t1
                                    #% Locb contains indices of t1 that are in t2
    final_p = p1(Locb); #% get the values of p1 where t2 existed in t1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have set a background on the data-role=page element like so <div data-role=page style=background:
BackGround: I have an advanced data grid. The data provider for this ADG is
I have a background worker thread that is constantly syncing data to/from a remote
Background I have an array of objects (Users) defined and set as follows: //
Background: XPage with tabbed table (from container controls) and multiple data sources, one for
I developed one android app which is having sets of activities and one background
I have a combobox which has ItemsSource set to an ObservableCollection property called DATA
Background Information I have a distributed processing application that does data analysis. It is
I have a DataGridCheckBoxColumn that I want to set the background color of the
I have an android app that will record data every x mins. The time

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.