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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:33:36+00:00 2026-06-12T08:33:36+00:00

In MATLAB, how could I combine two matrices of data measured at different frequencies

  • 0

In MATLAB, how could I combine two matrices of data measured at different frequencies such that the result is indexed at the higher frequency? Since the data measured at the lower frequency will have many unknown values in the result, I would like to replace them with the last known value in the matrix. There is a lot of data so a vectorized solution would be preferred. I’ve added some sample data below.

Given:

    index1  data1  index2  data2
    1       2.1    2       30.5
    2       3.3    6       32.0
    3       3.5    9       35.0
    4       3.9    13      35.5
    5       4.5    17      34.5
    6       5.0    20      37.0
    7       5.2    ...     ...
    8       5.7
    9       6.8
    10      7.9
    ...     ...

Result:

    index1  data1  data2
    1       2.1    NaN
    2       3.3    30.5
    3       3.5    30.5
    4       3.9    30.5
    5       4.5    30.5
    6       5.0    32.0
    7       5.2    32.0
    8       5.7    32.0
    9       6.8    35.0
    10      7.9    35.0
    ...     ...    ...

EDIT:
I think the following post is close to what I need, but I’m not sure how to transform the solution to fit my problem.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/260139

EDIT (Several Months Later):
I’ve recently come across this excellent little function that I think may be of use to anyone who lands on this post:

function yi = interpLast(x,y,xi)
%INTERPLAST Interpolates the input data to the last known value.
% Note the index data should be input in ASCENDING order.
inds = arrayfun(@findinds, xi);
yi = y(inds);

function ind = findinds(val)
    ind = find(x<=val,1,'last');
    if isempty(ind)
        ind = 1;
    end
end

end

Credit goes here: http://www.mathworks.com/support/solutions/en/data/1-48KETY/index.html?product=SL&solution=1-48KETY

  • 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-12T08:33:37+00:00Added an answer on June 12, 2026 at 8:33 am

    The problem is one of run length decoding. See section 15.5.2 of Matlab array manipulation tips and tricks (which is an eye-opening read for any Matlab enthusiast).

    Here’s using the method with your example (I’m using octave but the code is identical for Matlab):

    octave:33> a=[2,30.5;6,32;9,35;13,35.5;17,34.5;20,37]
    a =
    
        2.0000   30.5000
        6.0000   32.0000
        9.0000   35.0000
       13.0000   35.5000
       17.0000   34.5000
       20.0000   37.0000
    
    octave:34> i=a(:,1)-1
    i =
    
        1
        5
        8
       12
       16
       19
    
    octave:35> j=zeros(1,i(end))
    j =
    
       0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
    
    octave:36> j(i(1:end-1)+1)=1
    j =
    
       0   1   0   0   0   1   0   0   1   0   0   0   1   0   0   0   1   0   0
    
    octave:37> j(1)=1
    j =
    
       1   1   0   0   0   1   0   0   1   0   0   0   1   0   0   0   1   0   0
    
    octave:38> val=a(:,2)
    val =
    
       30.500
       32.000
       35.000
       35.500
       34.500
       37.000
    
    octave:39> x=val(cumsum(j))
    x =
    
       30.500
       32.000
       32.000
       32.000
       32.000
       35.000
       35.000
       35.000
       35.500
       35.500
       35.500
       35.500
       34.500
       34.500
       34.500
       34.500
       37.000
       37.000
       37.000
    

    And pad the beginning with NaN as needed.

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

Sidebar

Related Questions

Could anyone help how should I use the interp1-function on MATLAB on data such
I am struggling with declaring some more complex matrices in matlab, perhaps you could
I have a MATLAB GUI and a separate application that writes data to a
I have two matrices in MATLAB lets say arr1 and arr2 of size 1000*1000
Could we write an android client to ask for some data from Matlab output
In a pylab program (which could probably be a matlab program as well) I
I want to use some Python libraries to replace MATLAB. How could I import
Matlab documentation states that it is possible to replace the Nth occurrence of the
I have a simple Matlab program that uses a set of random number lists
I'm writing a MATLAB application which has many functions spread over different files. 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.