writing a script using linear interpolation eq. without hardcoding
4 views (last 30 days)
Show older comments
Ok so i have an excel spreadsheet with 4 different columns, one is the height(A) and the other three(Coefficients B,C,D) are values dependent on that height. I'm trying to write a code without using any of the interp1 function to input a height and and coefficient and correctly estimate the output at that given height. I've imported the data and indexed the arrays.
I know I need the program to use four values from two columns for linear interpolation. How would I code this correctly to store these values into the equation.
For example if I were to input a value of 33 ft for the first column to estimate a value in the 3rd column(C): and using fprintf I should get:The value of Kz at a height of 33 ft for Exposure C is 0.998.
Any help would be great,
Thanks
0 Comments
Answers (1)
Cindy Solomon
on 7 May 2015
Edited: Cindy Solomon
on 7 May 2015
Hi Angel,
Apologies- I'm not sure that I understand your question. To clarify, let's say you have imported your data from Excel into MATLAB into 4 vectors called Height, coefA, coefB, and coefC. Are you using the height and one of the coefficients to estimate values of the other coefficients, or are you just interpolating over a finer sampling range of height?
If the latter, take this doc example of interpolating a coarsely sampled sine function. Once the sample points, sample values, and query points have been input, you can store the results in a variable (in that doc example, this variable is called vq1).
If you then wanted to use fprintf for only value at a time, you could just do something like:
fprintf('The value of Kz at a height of %4.2f ft for Exposure C is %4.3f \n',queryPoint(1),vq1(1))
In your case, these variables could have more meaningful names to make it make more sense logically, such as coefC and interpCoefC, for examples.
Hope this helps!
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!