How do I interpolate cyclic data

14 Ansichten (letzte 30 Tage)
William From The Block
William From The Block am 25 Sep. 2017
Bearbeitet: KSSV am 26 Sep. 2017
Dear community,
I am using MATLAB 2016b on Windows 10. I am trying to interpolate data that is cyclic in nature but the built in "interp1" function in MATLAB dislikes repeating values in "x".
What I am trying to do:
I am trying to interpolate the "y" data from one cell of struct data with an "x" and "y" column with the "x" values from a separate struct data. Example: I have the following structs with arrays that are of size [n x 1], where n can differ between between structs sampleData{1}.X, sampleData{1}.Y, sampleData{2}.X, sampleData{2}.Y I want to do something to the effect of
interp1(sampleData{1}.X, sampleData{1}.Y, sampleData{2}.X)
so that I am using sampleData{1} data to interpolate values at sampleData{2}.X
What my script currently does:
  1. Takes my data files from a specified folder and reads them from that folder
  2. Assigns my data to structs
  3. Does some simple math with my arrays
  4. Checks the length of RHEDataMatrix{(2 *k)}.potential, my even array "x" data and compares it to RHEDataMatrix{(2 *k-1)}.potential, my odd array "x" data.
  • If they are the same length I interpolate the odd data using the even data "x" values, RHEDataMatrix{(2 *k)}.potential
  • If the length of the even data "x" values, RHEDataMatrix{(2 *k)}.potential, is greater than the length of the odd "x" data values I still interpolate the odd data using the even data "x" values.
  • If the length of the odd data "x" values, RHEDataMatrix{(2 *k-1)}.potential, is greater than the length of the even "x" data values then I interpolate the even data using the odd data "x" values.
Unfortuntely, the interp1 function does not like cyclic data where you may have more than one of the same "x" values. So I end up getting the following error(s):
Error using griddedInterpolant
The grid vectors must contain unique points.
Error in interp1 (line 161)
F = griddedInterpolant(X,V,method);
Error in myLoadCV12_20170915_justdellCV_FINALv3_deltaExample (line 53)
interpolatedMatrix{(2*k-1)}.current = interp1(RHEDataMatrix{(2*k-1)}.potential,
RHEDataMatrix{(2*k-1)}.current, RHEDataMatrix{(2*k)}.potential, 'linear' );
My current script (m file and sample data files are attached) and my closest guess to a possible solution would be to use the function "interparc" from here: https://www.mathworks.com/matlabcentral/fileexchange/34874-interparc

Antworten (1)

KSSV
KSSV am 26 Sep. 2017
Bearbeitet: KSSV am 26 Sep. 2017

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by