How to do an interpolation with more than one variables? " Error using matlab.int​ernal.math​.interp1 Sample points must be unique."

2 views (last 30 days)
Hello! I have a file with information (image 1). In matlab, I chose that file, read it and save the different columns as I want (image 2).
On data(:,1) which is my Phi angle I have values 0:5:360 and on data(:,2) which is my Theta angle I have values 0:5:180. In the file it looks like this:
0 0
0 5
0 10
0 15
... ...
0 180
5 0
5 5
5 10
... ...
5 180
... ...
360 0
360 5
... ...
360 180
So each combination of Phi and Theta have different values of E_phi and E_theta, which are the other columns.
My goal now is to do an interpolation to have, for example, the values of E_phi and E_theta for Phi = 0.6 and Theta = 1.2. For that I created the new arrays of Phi and Theta, called Phi_new and Theta_new, respectly. (You can see the code and results in images 3 and 4. I think it is correct, it is just for you to understand better).
So now I was doind this:
>> E_phi_new = interp1(Phi, E_phi, Phi_new, 'spline');
>> E_theta_new = interp1(Theta, E_theta, Theta_new, 'spline');
I discover that this is not possible because "Error using matlab.internal.math.interp1. Sample points must be unique." which makes sense. To do this I think I need both the variable Phi and Theta and not just one in each line. But I don't understand how to do it.
Have you got any suggestion? I am sorry for this big text, it is just to try to explain better my problem. In image 5 is the entire code, if it helps.
Thank you very much!

Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!