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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:33:38+00:00 2026-05-30T05:33:38+00:00

Do you know any C implementation of the Matlab interp1 function (just ‘linear’ one)?

  • 0

Do you know any C implementation of the Matlab interp1 function (just ‘linear’ one)? I know one for Java.

  • 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-30T05:33:40+00:00Added an answer on May 30, 2026 at 5:33 am

    I have implemented this linear interpolation myself (some of it is written in Spanish, sorry). The function called encuentraValorMasProximo just finds the nearest value (elementoMasProximo) and index (indiceEnVector) to another one (xx[i]), in an array (xD).

    void interp1(int *x, int x_tam, double *y, int *xx, int xx_tam, double *yy)
    {
    double *dx, *dy, *slope, *intercept, *elementoMasProximo, *xD;
    int i, *indiceEnVector;
    
    dx=(double *)calloc(x_tam-1,sizeof(double));
    dy=(double *)calloc(x_tam-1,sizeof(double));
    slope=(double *)calloc(x_tam-1,sizeof(double));
    intercept=(double *)calloc(x_tam-1,sizeof(double));
    indiceEnVector=(int *) malloc(sizeof(int));
    elementoMasProximo=(double *) malloc(sizeof(double));
    xD=(double *)calloc(x_tam,sizeof(double));
    
    for(i=0;i<x_tam;i++){
        xD[i]=x[i];
    }
    
    for(i = 0; i < x_tam; i++){
        if(i<x_tam-1){
            dx[i] = x[i + 1] - x[i];
            dy[i] = y[i + 1] - y[i];
            slope[i] = dy[i] / dx[i];
            intercept[i] = y[i] - x[i] * slope[i];
        }else{
            dx[i]=dx[i-1];
            dy[i]=dy[i-1];
            slope[i]=slope[i-1];
            intercept[i]=intercept[i-1];
        }
    }
    
    for (i = 0; i < xx_tam; i++) {
        encuentraValorMasProximo(xx[i], xD, x_tam, x_tam, elementoMasProximo, indiceEnVector);
        yy[i]=slope[*indiceEnVector] * xx[i] + intercept[*indiceEnVector];
    }
    }
    

    The test function could be:

    void main(){
    
    int x_tam, xx_tam, i;
    double *yy;
    int x[]={3,6,9};
    double y[]={6,12,18};
    int xx[]={1,2,3,4,5,6,7,8,9,10};
    x_tam=3;
    xx_tam=10;
    yy=(double *) calloc(xx_tam,sizeof(double));
    
    interp1(x, x_tam, y, xx, xx_tam, yy);
    
    for(i=0;i<xx_tam;i++){
        printf("%d\t%f\n",xx[i],yy[i]);
    }
    
    }
    

    And its outcome:

    1 2.000000

    2 4.000000

    3 6.000000

    4 8.000000

    5 10.000000

    6 12.000000

    7 14.000000

    8 16.000000

    9 18.000000

    10 20.000000

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

Sidebar

Related Questions

Do you know any implementation, (java) to solve non linear programming with this algorithm?
Do you know any function implementation I could use for decrypting data encrypted by
Does any one know if there is kinda implementation/addon for VS 2008 SP1 for
Do you know any java implementation of the Porter2 stemmer(or any better stemmer written
Do you know any implementation / technique which would provide similar behavior as Viewstate
Does anyone know of any HMM implementation in .net? I've some stuff that I
Do anyone know any incremental implementation of decision tree classifier. Such that it could
Is there any implementation of scanf()(like in C) in awk(POSIX)? I know that awk
I know this might sound awful. Is there any implementation of .NET for Mac
Does anyone know of a Python replacement for Matlab / Octave bwdist() function? This

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.