Error using matlab.internal.math.interp1 sample points must be unique.

I'm using Kilosort for NeuroNexus 32 channel linear probes, and I'm getting this error during pre-processing:

Error using matlab.internal.math.interp1
Sample points must be unique and sorted in ascending order.

Error in interp1 (line 188)
VqLite = matlab.internal.math.interp1(X,V,method,method,Xqcol);

Error in shift_batch_on_disk2 (line 14)
shifts = interp1(ysamp, shifts, rez.yc, 'makima', 'extrap');

Error in datashift2 (line 149)
dprev = shift_batch_on_disk2(rez, ibatch, dshift(ibatch, :), yblk, sig, dprev);

Error in ksGUI/runPreproc (line 732)
obj.rez = datashift2(obj.rez, 1);

Error in ksGUI>@(,)obj.runPreproc() (line 333)
'Callback', @(,)obj.runPreproc());

Error while evaluating UIControl Callback.


When I work around this error, I get another error during spike sorting:

Error using gpuArray/subsref
Subscript indices must either be real positive integers or logicals.

Error in extractTemplatesfromSnippets (line 56)
wTEMP = dd(:, round(linspace(1, size(dd,2), nPCs)));

Error in extract_spikes (line 42)
[wTEMP, wPCA] = extractTemplatesfromSnippets(rez, NrankPC);

Error in ksGUI/runSpikesort (line 795)
[obj.rez, st3, tF] = extract_spikes(obj.rez);

Error in ksGUI>@(,)obj.runSpikesort() (line 339)
'Callback', @(,)obj.runSpikesort());

Error while evaluating UIControl Callback.

You can remove duplicates (the first value is kept) with

time = [0,60,60,120,180,240,300,360,420,480,540];
data = [18,12,12,0,7,9,6,8,12,18,0];
[time_u unique_indeces] = unique(time);
data_u = data(unique_indeces);
clear unique_indeces;

and interpolate with

time_i = linspace(min(time), max(time), max(time) - min(time) + 1);
data_i = interp1(time_u, data_u, time_i);

I prefer linspace because I usually want to set the number of data points and not the space between points but you can also use min(time):max(time) or time(1):time(end) instead.

This code will also sort your data points by time.

I am using MATLAB to process and evaluate reflection coefficients of antennas.

The data is saved and used as an Mx2 array, where the M is the length of the x-axis data points, (or sample points). The first coloumn contains the values of the frequency points and the second coloumn contains the corresponding reflection coefficient values.

I use the 'interp1' function, which worked for the arrays of length 501, but the other array sized, 402, 404, 408 and 505, the following error occurs:

Error using matlab.internal.math.interp1

Sample points must be unique and sorted in ascending order.

Error in interp1 (line 188)

VqLite = matlab.internal.math.interp1(X,V,method,method,Xqcol);

I checked, and my sample points are unique and in ascending order, but the error still persists.

Here is a little snippet of the data

Sample point Reflection coefficient value

200 0.979472485068518

204.500000000000 0.977219575869647

209 0.974701356449019

213.500000000000 0.971883119143293

218 0.968724759813479

222.500000000000 0.965179866285502

227 0.961194345460292

231.500000000000 0.956704944454534

236 0.951637259422883

240.500000000000 0.945903325003744

245 0.939398658119580

Any and all help will be greatly appreciated.

Error using matlab.internal.math.interp1 sample points must be unique.

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)

See Also

Categories

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.