How do I interpolate cyclic data

5 visualizaciones (últimos 30 días)
William From The Block
William From The Block el 25 de Sept. de 2017
Editada: KSSV el 26 de Sept. de 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

Respuestas (1)

KSSV
KSSV el 26 de Sept. de 2017
Editada: KSSV el 26 de Sept. de 2017

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by