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); endfigure%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 ongrid ongrid minorax = 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 endend
Which did not find any values less than negative. Any ideas why its throwing this error?
Tom
Best Answer