Rank: 677 based on 102 downloads (last 30 days) and 9 files submitted
photo

Steve Simon

E-mail
Company/University
The MathWorks

Personal Profile:

As part of the technical support staff, I answer questions. I have also contributed to the development of the Bioinformatics Toolbox, particularly the file I/O and graphics functions.

Professional Interests:

 

Watch this Author's files

 

Files Posted by Steve View all
Updated   File Tags Downloads
(last 30 days)
Comments Rating
18 Nov 2010 Screenshot SCATTERCLOUD Scatterplot over a density cloud. Author: Steve Simon cloud, density, specialized, plotting, scatter, graphics 65 12
  • 4.54545
4.5 | 13 ratings
26 May 2006 LEGENDTITLE Add a title string inside a legend. Author: Steve Simon annotation, legend, graphics, title, axes, legend title 24 13
  • 3.1
3.1 | 10 ratings
17 Sep 2004 SPINNER Create a simple spinner control using 3 uicontrols. Author: Steve Simon gui tools, example, gui, spinner, control, edit 3 0
30 Mar 2004 AUTOSAVE Automatically save variables from base workspace. Author: Steve Simon autosave, automatic, save, variables, timer 3 0
24 Oct 2003 CITYPLOT Create 'cityplot' graphics. Author: Steve Simon specialized, plotting, cityplot, create, graphics, city 0 0
  • 5.0
5.0 | 1 rating
Comments and Ratings on Steve's Files View all
Updated File Comment by Comments Rating
23 Aug 2011 SCATTERCLOUD Scatterplot over a density cloud. Author: Steve Simon G, J

This would be really useful for scatter3 too, any suggestions how I could do that?

15 Jul 2011 SCATTERCLOUD Scatterplot over a density cloud. Author: Steve Simon G, J

Very cool function. Can it be done on a 3D scatter plot?

25 Apr 2011 SCATTERCLOUD Scatterplot over a density cloud. Author: Steve Simon BLu

It works well for small datasets and small n (such as 50).
I added a none option, as suggested above and changed the centering problem as suggested above.
I tried a large dataset and n=200, and have to terminate the calculation because it is taking too long. The code used in calculating the counts is not the most efficient. cloudPlot has a much more efficient algorithm. I made modification based on cloudPlot.

error(nargchk(2,6,nargin),'struct');

x = x(:);
y = y(:);

%new code
pointSelect = isinf(x) | isnan(x) | isinf(y) | isnan(y);
x = x(~pointSelect);
y = y(~pointSelect);
%new code ends

if length(x) ~= length(y)
    error('SCATTERCLOUDDataVectorSizesDoNotMatch','The number of elements in x and y do not match')
end

if nargin < 6
    %cmap = flipud(gray(256));
    cmap='default';
end

if nargin < 5
    %clm = 'k+';
    clm='none';
end

if nargin < 4
    l = 1;
end

if nargin < 3
    n = 25;
end

% min/max of x and y
minX = min(x);
maxX = max(x);
minY = min(y);
maxY = max(y);

% edge locations
xEdges = linspace(minX,maxX,n);
yEdges = linspace(minY,maxY,n);

% shift edges
xDiff = xEdges(2) - xEdges(1);
yDiff = yEdges(2) - yEdges(1);
xEdges = [-Inf, xEdges(2:end) - xDiff/2, Inf];
yEdges = [-Inf, yEdges(2:end) - yDiff/2, Inf];

% number of edges
numX = numel(xEdges);
numY = numel(yEdges);

%new code
xBinIndex = floor((x - minX+xDiff/2)/xDiff)+1;
yBinIndex = floor((y - minY+yDiff/2)/yDiff)+1;
%new code ends
    
% hold counts
C = zeros(numY,numX);

% do counts
%new code
for i=1:numel(x)
    C(yBinIndex(i),xBinIndex(i))=C(yBinIndex(i),xBinIndex(i))+1;
end
%new code ends

%for i = 1:numY-1
% for j = 1:numX-1
% C(i,j) = sum(x >= xEdges(j) & x < xEdges(j+1) &...
% y >= yEdges(i) & y < yEdges(i+1));
% end
% disp(num2str(i));
%end

% get rid of Infs from the edges
xEdges = [xEdges(2) - xDiff,xEdges(2:end-1), xEdges(end-1) + xDiff] + xDiff/2;
yEdges = [yEdges(2) - yDiff,yEdges(2:end-1), yEdges(end-1) + yDiff] + yDiff/2;

%xEdges = [xEdges(2) - xDiff,xEdges(2:end-1), xEdges(end-1) + xDiff];
%yEdges = [yEdges(2) - yDiff,yEdges(2:end-1), yEdges(end-1) + yDiff];

% smooth the density data, in both directions.
C = localSmooth(localSmooth(C,l)',l)';

% create the graphics
ax = newplot;
s = surf(xEdges,yEdges,zeros(numY,numX),C,...
         'EdgeColor','none',...
         'FaceColor','interp');
view(ax,2);
colormap(ax,cmap);
grid(ax,'off');
holdstate = get(ax,'NextPlot');
set(ax,'NextPlot','add');

if ~strcmpi(clm,'none')
    p = plot(x,y,clm);
end

axis(ax,'tight');
set(ax,'NextPlot',holdstate)

% outputs
if nargout
    h = [s;p];
end

function B = localSmooth(A,L)
r = size(A,1);
I = eye(r);
D1 = diff(I);
D2 = diff(I,2);
B = (I + L ^ 2 * D2' * D2 + 2 * L * D1' * D1) \ A;

 

27 Mar 2011 SCATTERCLOUD Scatterplot over a density cloud. Author: Steve Simon G, J

works great thanks!

01 Feb 2011 SCATTERCLOUD Scatterplot over a density cloud. Author: Steve Simon Caywood, Matt

To fix the glaring centering bug, change these lines from:

xEdges = [xEdges(2) - xDiff,xEdges(2:end-1), xEdges(end-1) + xDiff];
yEdges = [yEdges(2) - yDiff,yEdges(2:end-1), yEdges(end-1) + yDiff];

TO:

xEdges = [xEdges(2) - xDiff,xEdges(2:end-1), xEdges(end-1) + xDiff] + xDiff/2;
yEdges = [yEdges(2) - yDiff,yEdges(2:end-1), yEdges(end-1) + yDiff] + yDiff/2;

In the future, if there's a "simple" fix, why not post it and be helpful?

Top Tags Applied by Steve
graphics, annotation, customization, plot, biotech
Files Tagged by Steve View all
Updated   File Tags Downloads
(last 30 days)
Comments Rating
18 Nov 2010 Screenshot SCATTERCLOUD Scatterplot over a density cloud. Author: Steve Simon cloud, density, specialized, plotting, scatter, graphics 65 12
  • 4.54545
4.5 | 13 ratings
26 May 2006 LEGENDTITLE Add a title string inside a legend. Author: Steve Simon annotation, legend, graphics, title, axes, legend title 24 13
  • 3.1
3.1 | 10 ratings
17 Sep 2004 SPINNER Create a simple spinner control using 3 uicontrols. Author: Steve Simon gui tools, example, gui, spinner, control, edit 3 0
30 Mar 2004 AUTOSAVE Automatically save variables from base workspace. Author: Steve Simon autosave, automatic, save, variables, timer 3 0
24 Oct 2003 CITYPLOT Create 'cityplot' graphics. Author: Steve Simon specialized, plotting, cityplot, create, graphics, city 0 0
  • 5.0
5.0 | 1 rating

Contact us at files@mathworks.com