File Exchange

image thumbnail

Flow Cytometry Data Reader and Visualization

version (189 KB) by Robert Henson
Flow Cytometry Data Reader and Visualization Example


Updated 01 Sep 2016

View Version History

View License

This includes a function to read in the standard flow cytometry FCS format data and examples of how to visualize the data.

Cite As

Robert Henson (2021). Flow Cytometry Data Reader and Visualization (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (24)

Loriann Chevalier

Is it possible to set the x-axis to be logarithmic as well ?

Sumera Yamin

Hi, Thanks for the nice function. I want to use this function dscatter, but i am getting this error
"Error using min
Invalid data type. First
argument must be numeric or

Error in dscatter (line 108)
minx = min(X,[],1);".

Please let me know how to rectify the error.

Yong Hong Tan

Error using accumarray
First input SUBS and third input SZ must satisfy ALL(MAX(SUBS)<=SZ).

Error in dscatter (line 134)
H = accumarray(bin,1,nbins([2 1])) ./ n;

Nick Lee

To solve the problem of
'Error using reshape
Size arguments must be real integers.

Error in fcsread (line 81)
textHeader = reshape(textCell,2,numel(textCell)/2);'

You need to check the delimiter of the header. The sample fcs uses '\' as delimiter, but my fcs file uses '!' as demiliter. So change the line 77 code into
textCell = strread(textData,'%s','delimiter','!');
will solve the problem.

Good luck!

valeria galli

I get 'undefined function or variable' for smooth1D, should I install some toolbox to get it?

Arthur Barker

I also get the error;

'Error using reshape
Size arguments must be real integers.

Error in fcsread (line 81)
textHeader = reshape(textCell,2,numel(textCell)/2);'

with both 2.0, 3.0 and 3.1 files.
Any suggestions on how to solve this issue?

Ariosto Silva

Rebecca, I am having the same issue as you with a version 3.0 file. Were you able to find a workaround?
Thank you

Rebecca Grant

I get this error when trying to read my file in 2.0 and 3.0 format - any help?

Error using reshape
Size arguments must be real integers.

Error in fcsread (line 81)
textHeader = reshape(textCell,2,numel(textCell)/2)';

Sébastien MAILFERT

Thanks for this code.
I would like to plot not in log scale the Y value (not for FACS data) but this does not show what I expected. The Y scale is Strange. Could you help me?

Hector Munoz

For anyone who is getting errors when trying to change marker size/markers, there is a mismatch in the switch-case structure starting at line 78.

case 5 should match up with 'marker' in okargs, but instead relates to contourFlag. I removed the case for contourFlag and renumbered the rest of the cases.

case 5
contourFlag = pval;
case 6
marker = pval;
case 7
msize = pval;
case 8
filled = pval;

case 5
marker = pval;
case 6
msize = pval;
case 7
filled = pval;

It would be interesting to have both an absolute and relative colorbar, that tell you how many values or % of values there are for every color respectively. The [0,1] default colorbar doesn't seem to give much information. For the rest, it works fine.

MD Shamim Ahmmed

Thanks for the nice code. In the color bar the range I am getting is 0 to 1. Could you please tell me what this 1 means? One more thing I need to get a contour enclosing 50% of data points, can any one help? Thanks.


very good,

Ian Williamson

Will the fcsread function work for fcs3.0 file type?

Peyman Obeidy

I get this error

Error using reshape
Size arguments must be real integers.

Error in fcsread (line 81)
textHeader = reshape(textCell,2,numel(textCell)/2)';

Chad Greene

The dscatter function is insanely fast and well written. It's beautifully documented and easy to use.

I used dscatter on a 1.5 million point dataset and the only bottleneck in processing is Matlab's scatter command. So I replaced the line of code which calls scatter and instead I'm using Aslak Grinsted's fastscatter, which is available on File Exchange. Here's what I replaced it with:

h = fastscatter(X,Y,col,'markersize',msize);

Now, dscatter takes 0.37 seconds to calculate and plot 1.5 million points. That's quite good.

The input parser wasn't detecting my request to set the marker size, so I added this to line 105:

tmp = strcmpi(varargin,'msize');
if any(tmp)
msize = varargin{find(tmp)+1};
msize = 10;

Thanks for writing and sharing this clever, efficient code, Robert!

Martin Ziegler

I am getting an error, when using the dscatter function:
Error using histc
Edge vector must be monotonically non-decreasing

Any idea on what might be causing it?



The file return errors for input with NaN values (not necessary a bad thing).

F Poelwijk

F Poelwijk


cool, but I cannot seem to set the marker size or non filled markers. Works fine with 'plot' mesh or grid, but not with 'msize:
>> h = dscatter(X, Y, 'msize', 20);
Error using scatter (line 53)
Too many input arguments.

Error in dscatter (line 170)
h =

It would also be nice if one could generate a gapless 2D image/array with the "density" as entries. Like the 2d projection of what ('plot', 'surf') actualy gives you.

On top of that I'd recommend catching the input "error" of horizontal vectors instead of vertical. It gives the user an error about equal sizes, you should just check for that and rotate the vectors if necessary ;)

Raz Shimoni

Sean Wang

Finally! I've been waiting for a long time

MATLAB Release Compatibility
Created with R14SP2
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired: Ratiometric FRET, FlowPlot, TACTICS Toolbox

Community Treasure Hunt

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

Start Hunting!