Error: Cannot set support to 'positive' with non-positive data.

7 views (last 30 days)
I continue to get the following error with my code:
Error using mvksdensity>compute_finite_support (line 274)
Cannot set support to 'positive' with non-positive data.
Error in mvksdensity (line 102)
[L,U] = compute_finite_support(support,ymin,ymax,d);
Error in ksdensity (line 226)
[fout,xout,u,plottype] = mvksdensity(yData,xi,varargin{:});
Error in collisions (line 537)
[f,xi] = ksdensity(cpdradial,'Support','positive','Censoring',cens,'NumPoints',10000);
I am running this code on data (attached file: 'dataset.met') to try and produce a density plot:
cpdcart = [];
for cpdtran2 = 1:particlecount
cpdcart = [cpdcart; collpos(cpdtran2).matrix(:,1:3)];
end
[cpdcol1,cpdrow1] = size(cpdcart);
cpdpolar = zeros(cpdcol1,2);
cpdradial = zeros(cpdcol1,1);
cpdphi = zeros(cpdcol1,1);
for cpdtran3 = 1:cpdcol1
cpdpolar(cpdtran3,1) = sqrt(cpdcart(cpdtran3,1).^2 + cpdcart(cpdtran3,2).^2 + cpdcart(cpdtran3,3).^2);
cpdradial(cpdtran3,1) = cpdpolar(cpdtran3,1);
cpdpolar(cpdtran3,2) = acos(cpdcart(cpdtran3,3)/cpdpolar(cpdtran3,1));
cpdphi(cpdtran3,1) = cpdpolar(cpdtran3,2);
end
figure
%Plot collisions depending only on radius
cens = (cpdradial<0.02);
[f,xi] = ksdensity(cpdradial,'Support','positive','Censoring',cens,'NumPoints',10000);
plot(xi,f,'w')
set(gca,'color','k')
xlabel 'Radial Distance (m) from Center of Sphere'
ylabel 'Collision Coordinate Density'
title({'Collision Coordinate Density vs Radial Distance',sprintf('Cross Section (m^2): %d',cs),sprintf('Temp (K): %d',ict),sprintf('Pressure (mTorr): %d',mTorr),sprintf('Time Span (sec): %d',tfin)})
hold on
grid on
grid minor
ax = gca;
ax.GridColor = 'w';
ax.MinorGridColor = 'w';
I know that my data is positive because I used the following for loop to determine if there were any negative values:
for checkneg = 1:164100
if cpdradial(checkneg,1) < 0
disp(cpdradial(checkneg,1))
else
end
end
Which did not find any values less than negative. Any ideas why its throwing this error?
Tom

Accepted Answer

the cyclist
the cyclist on 30 May 2019
Edited: the cyclist on 30 May 2019
You've checked that your data are non-negative, not they're positive. I'm guessing that you have zeros, and the positive-support requirement means strictly positive, not just non-negative.
  3 Comments
the cyclist
the cyclist on 30 May 2019
My intuition is that if you do not have a radical change in probability density between zero and very small values, then it should not be too bad as an approximation.
I suppose you could add a very tiny positive value to all your points, to nudge those zeros to positive, to see what the impact is.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!