Rank: 281 based on 220 downloads (last 30 days) and 8 files submitted
Personal Profile:
Professional Interests:

 

Watch this Author's files

 

Files Posted by Daniel View all
Updated   File Tags Downloads
(last 30 days)
Comments Rating
20 Sep 2011 Screenshot Matlab Freedom The wave equation applied to the matlab logo, with fewer constraints. Author: Daniel Armyr logo, wave equation, movie, animation, matlab 15 5
  • 4.0
4.0 | 3 ratings
13 May 2011 Screenshot cloudPlot A function to plot the distribution of 2-dimensional data. Author: Daniel Armyr scatter, cloud, visualize, plot 45 14
  • 5.0
5.0 | 8 ratings
18 May 2010 Published MATLAB Files abSIRD for Matlab Converts a depth-map into a random dot autostereogram. Author: Daniel Armyr sis, sird, random dot stereogram, autostereogram 8 1
  • 5.0
5.0 | 1 rating
14 Apr 2009 Screenshot Polar 2 An update to Matlabs built-in polar.m Author: Daniel Armyr antenna, graph types, polar, plotting, plot, graphics 86 12
  • 5.0
5.0 | 2 ratings
24 Mar 2009 Advanced Polar Plots v2 An improved version of the MATLAB function 'polar'. Author: Daniel Armyr antenna, plotting, graphics, graph types, polar, plot 59 18
  • 5.0
5.0 | 2 ratings
Comments and Ratings by Daniel View all
Updated File Comments Rating
09 Jan 2012 cloudPlot A function to plot the distribution of 2-dimensional data. Author: Daniel Armyr

Hi.
That is a pretty good idea. I will take it into consideration, but for now, here is a quick hack that will give you what you are looking for.

Use it the same way that you use the original function, only add a final argument (scaleFactor) that tells the function what scale factor to apply. If you want a density function, you set the last argument to 1/numel(X). In order to avoid extensive recoding, you will have to provide all the other arguments in order to use a scaling factor.

Example of density plot of random data
nPoints = 1e5;
clpoudPlot ( randn(nPoints,1), randn(nPoints,1), [], false, [], 1/nPoints );

--

function [ varargout ] = cloudPlot( X, Y, axisLimits, useLogScale, bins, scaleFactor )

% Check the data size
assert ( numel(X) == numel(Y), ...
    'The number of elements in X and Y must be the same.' );

if ( nargin >= 3 && ~isempty(axisLimits) )
    pointSelect = X<=axisLimits(2) & X>=axisLimits(1) & ...
        Y<=axisLimits(4) & Y>=axisLimits(3);
    X = X(pointSelect);
    Y = Y(pointSelect);
    axisLimitsSet = true;
else
    axisLimitsSet = false;
end

if ( nargin < 4 || isempty(useLogScale) )
    useLogScale = false;
end

if ( nargin < 5 )
    bins = [];
end

  
%Remove any nans or Infs in the data as they have no meaning in this
%context.
pointSelect = ~(isinf(X) | isnan(X) | isinf(Y) | isnan(Y));
X = X(pointSelect);
Y = Y(pointSelect);
    
% Plot to get appropriate limits
h = [];
if ( axisLimitsSet )
    g = gca;
    set ( g, 'Xlim', [axisLimits(1) axisLimits(2)] );
    set ( g, 'Ylim', [axisLimits(3) axisLimits(4)] );
    set ( g, 'units', 'pixels' );
else
    h = plot ( X(:), Y(:), '.' );
    g = get( h, 'Parent' );
end
xLim = get(g, 'Xlim' );
yLim = get(g, 'Ylim' );

%Get the bin size.
unitType = get(g,'Unit');
set(g,'Unit','Pixels')
axesPos = get(g,'Position');
nHorizontalBins = axesPos(3);
nVerticalBins = axesPos(4);
set(g,'Unit', unitType );

% Clear the data, as we actually don't want to see it.
if ( ~isempty(h) )
    set ( h, 'XData', [] );
    set ( h, 'YData', [] );
end

% Allocate an area to draw on
if ( isempty(bins) )
    bins = ceil([nHorizontalBins nVerticalBins ]);
else
    assert ( isnumeric(bins) && isreal(bins) );
    assert ( numel(bins) == 2 );
end
binSize(2) = diff(yLim)./(bins(2));
binSize(1) = diff(xLim)./(bins(1));

canvas = zeros(bins);

% Draw in the canvas
xBinIndex = floor((X - xLim(1))/binSize(1))+1;
yBinIndex = floor((Y - yLim(1))/binSize(2))+1;

% Added security: Make sure indexes are never outside canvas. May not be
% possible.
pointsSelect = xBinIndex > 0 & xBinIndex <= bins(1) & ...
    yBinIndex > 0 & yBinIndex <= bins(2);
xBinIndex = xBinIndex(pointsSelect);
yBinIndex = yBinIndex(pointsSelect);

for i = 1:numel(xBinIndex);
    canvas(xBinIndex(i),yBinIndex(i)) = ...
        canvas(xBinIndex(i),yBinIndex(i)) + 1;
end

% Show the canvas and adjust the grids.
if ( useLogScale )
    h = imagesc(xLim, yLim,log10(canvas*scaleFactor)');
else
    h = imagesc(xLim, yLim, canvas'*scaleFactor);
end

axis ( 'xy' );
axis ( 'tight' );
set ( g, 'units', 'normalized' ); % Enable resizing

% Optionally return a handle.
if ( nargout == 1)
    varargout{1} = h;
end

04 Aug 2011 cloudPlot A function to plot the distribution of 2-dimensional data. Author: Daniel Armyr

JG: I your data is 1D, then this function is not for you. Read up on the details of hist() in the documentation and you will find that Hist can do what you are looking for.

23 May 2011 Matlab Freedom The wave equation applied to the matlab logo, with fewer constraints. Author: Daniel Armyr

Added the source code and rerendered the film to remove some glitches.

23 May 2011 Advanced Polar Plots v2 An improved version of the MATLAB function 'polar'. Author: Daniel Armyr

As mentioned, use http://www.mathworks.com/matlabcentral/fileexchange/23589 instead.

13 May 2011 cloudPlot A function to plot the distribution of 2-dimensional data. Author: Daniel Armyr

Of course you are right. New version with better scaling, support for hold states, and support for manual setting of transparency. See the published demo file for examples.

Comments and Ratings on Daniel's Files View all
Updated File Comment by Comments Rating
09 Jan 2012 cloudPlot A function to plot the distribution of 2-dimensional data. Author: Daniel Armyr Armyr, Daniel

Hi.
That is a pretty good idea. I will take it into consideration, but for now, here is a quick hack that will give you what you are looking for.

Use it the same way that you use the original function, only add a final argument (scaleFactor) that tells the function what scale factor to apply. If you want a density function, you set the last argument to 1/numel(X). In order to avoid extensive recoding, you will have to provide all the other arguments in order to use a scaling factor.

Example of density plot of random data
nPoints = 1e5;
clpoudPlot ( randn(nPoints,1), randn(nPoints,1), [], false, [], 1/nPoints );

--

function [ varargout ] = cloudPlot( X, Y, axisLimits, useLogScale, bins, scaleFactor )

% Check the data size
assert ( numel(X) == numel(Y), ...
    'The number of elements in X and Y must be the same.' );

if ( nargin >= 3 && ~isempty(axisLimits) )
    pointSelect = X<=axisLimits(2) & X>=axisLimits(1) & ...
        Y<=axisLimits(4) & Y>=axisLimits(3);
    X = X(pointSelect);
    Y = Y(pointSelect);
    axisLimitsSet = true;
else
    axisLimitsSet = false;
end

if ( nargin < 4 || isempty(useLogScale) )
    useLogScale = false;
end

if ( nargin < 5 )
    bins = [];
end

  
%Remove any nans or Infs in the data as they have no meaning in this
%context.
pointSelect = ~(isinf(X) | isnan(X) | isinf(Y) | isnan(Y));
X = X(pointSelect);
Y = Y(pointSelect);
    
% Plot to get appropriate limits
h = [];
if ( axisLimitsSet )
    g = gca;
    set ( g, 'Xlim', [axisLimits(1) axisLimits(2)] );
    set ( g, 'Ylim', [axisLimits(3) axisLimits(4)] );
    set ( g, 'units', 'pixels' );
else
    h = plot ( X(:), Y(:), '.' );
    g = get( h, 'Parent' );
end
xLim = get(g, 'Xlim' );
yLim = get(g, 'Ylim' );

%Get the bin size.
unitType = get(g,'Unit');
set(g,'Unit','Pixels')
axesPos = get(g,'Position');
nHorizontalBins = axesPos(3);
nVerticalBins = axesPos(4);
set(g,'Unit', unitType );

% Clear the data, as we actually don't want to see it.
if ( ~isempty(h) )
    set ( h, 'XData', [] );
    set ( h, 'YData', [] );
end

% Allocate an area to draw on
if ( isempty(bins) )
    bins = ceil([nHorizontalBins nVerticalBins ]);
else
    assert ( isnumeric(bins) && isreal(bins) );
    assert ( numel(bins) == 2 );
end
binSize(2) = diff(yLim)./(bins(2));
binSize(1) = diff(xLim)./(bins(1));

canvas = zeros(bins);

% Draw in the canvas
xBinIndex = floor((X - xLim(1))/binSize(1))+1;
yBinIndex = floor((Y - yLim(1))/binSize(2))+1;

% Added security: Make sure indexes are never outside canvas. May not be
% possible.
pointsSelect = xBinIndex > 0 & xBinIndex <= bins(1) & ...
    yBinIndex > 0 & yBinIndex <= bins(2);
xBinIndex = xBinIndex(pointsSelect);
yBinIndex = yBinIndex(pointsSelect);

for i = 1:numel(xBinIndex);
    canvas(xBinIndex(i),yBinIndex(i)) = ...
        canvas(xBinIndex(i),yBinIndex(i)) + 1;
end

% Show the canvas and adjust the grids.
if ( useLogScale )
    h = imagesc(xLim, yLim,log10(canvas*scaleFactor)');
else
    h = imagesc(xLim, yLim, canvas'*scaleFactor);
end

axis ( 'xy' );
axis ( 'tight' );
set ( g, 'units', 'normalized' ); % Enable resizing

% Optionally return a handle.
if ( nargout == 1)
    varargout{1} = h;
end

07 Jan 2012 cloudPlot A function to plot the distribution of 2-dimensional data. Author: Daniel Armyr universdity, texas A&M

Great Code Daniel.

Can you please suggest how I can obtain probability density instead of histogram in your Code or How I can divide the frequency in all the bins with a constant number.

Thank you

Sireesh Dadi

20 Oct 2011 Matlab Freedom The wave equation applied to the matlab logo, with fewer constraints. Author: Daniel Armyr Smart, Mr
08 Aug 2011 Matlab Freedom The wave equation applied to the matlab logo, with fewer constraints. Author: Daniel Armyr Martin

nice

04 Aug 2011 cloudPlot A function to plot the distribution of 2-dimensional data. Author: Daniel Armyr Armyr, Daniel

JG: I your data is 1D, then this function is not for you. Read up on the details of hist() in the documentation and you will find that Hist can do what you are looking for.

Top Tags Applied by Daniel
plot, polar, antenna, graph types, graphics
Files Tagged by Daniel View all
Updated   File Tags Downloads
(last 30 days)
Comments Rating
20 Sep 2011 Screenshot Matlab Freedom The wave equation applied to the matlab logo, with fewer constraints. Author: Daniel Armyr logo, wave equation, movie, animation, matlab 15 5
  • 4.0
4.0 | 3 ratings
13 May 2011 Screenshot cloudPlot A function to plot the distribution of 2-dimensional data. Author: Daniel Armyr scatter, cloud, visualize, plot 45 14
  • 5.0
5.0 | 8 ratings
18 May 2010 Published MATLAB Files abSIRD for Matlab Converts a depth-map into a random dot autostereogram. Author: Daniel Armyr sis, sird, random dot stereogram, autostereogram 8 1
  • 5.0
5.0 | 1 rating
14 Apr 2009 Screenshot Polar 2 An update to Matlabs built-in polar.m Author: Daniel Armyr antenna, graph types, polar, plotting, plot, graphics 86 12
  • 5.0
5.0 | 2 ratings
24 Mar 2009 Advanced Polar Plots v2 An improved version of the MATLAB function 'polar'. Author: Daniel Armyr antenna, plotting, graphics, graph types, polar, plot 59 18
  • 5.0
5.0 | 2 ratings

Contact us at files@mathworks.com