Linear Interpolation in MATLAB: Troubleshooting and Tips

Click For Summary

Discussion Overview

The discussion revolves around troubleshooting MATLAB code for linear interpolation using the interp1 function. Participants explore issues related to the choice of interpolation method, data formatting, and output display.

Discussion Character

  • Technical explanation, Homework-related, Exploratory

Main Points Raised

  • One participant shares their MATLAB code for interpolation and expresses confusion about the next steps.
  • Another participant questions the use of the 'pchip' parameter, suggesting it is for cubic interpolation and proposes an alternative approach.
  • A participant acknowledges the need to use linear interpolation instead of cubic.
  • There is a request for examples of displaying data in a table format.
  • One participant indicates they are struggling with outputting results in a table format, expressing frustration about only receiving the last values.
  • A suggestion is made to explore the array2table() function as a potential solution for displaying data.

Areas of Agreement / Disagreement

Participants generally agree on the need to use linear interpolation, but there is no consensus on the best way to format and display the output data.

Contextual Notes

Participants have not resolved the specific issues related to output formatting and the use of the interp1 function, including the implications of using different interpolation methods.

Who May Find This Useful

Individuals working with MATLAB for data interpolation, particularly those seeking assistance with coding and output formatting.

ineedhelpnow
Messages
649
Reaction score
0
View attachment 5032hi! here's my question. here's my code. i have no idea what to do now :(

Code:
x = 0:9;
y = [0.053 1.477 1.970 3.279 4.153 4.934 5.178 5.828 6.082 6.484]; % data
X = linspace(0,8.5,1);
Y = interp1(x,y,X,'pchip')
 

Attachments

  • Untitled.png
    Untitled.png
    12.9 KB · Views: 138
Physics news on Phys.org
I know nothing about MATLAB, but isn't the parameter [m]'pchip'[/m] used for cubic interpolation?

It seems to be after looking at the MATLAB documentation, we want to begin with code like:

Code:
v = [0.053 1.477 1.970 3.279 4.153 4.934 5.178 5.828 6.082 6.484];
xq = 0.5:8.5;
vq = interp1(v,xq);
 
thank you :) yeah it should have been linear
 
ineedhelpnow said:
thank you :) yeah it should have been linear

Do you have any examples where data is displayed in a table format?
 
no :( that's mainly what I am stuck on
 
ineedhelpnow said:
no :( that's mainly what I am stuck on

It looks like the [m]array2table()[/m] function could be a place to look. :D
 
Thank You! There's another problem with my code. Like when I print it I'll only get the last values. Not a table of values
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K