For most scientists, there is a ton of utility in switching between colormaps. Here I describe a less commonly-used method to get even more from your colormap.
If you’re like me and you learn by reading code, feel free to skip to the end for a code snippet from MATLAB.
You have data you want to display, but most of the values are much smaller than the overall range of values. This can give you the sense that there’s “nothing there” in your image when actually there may be interesting variability that you’re not seeing.
Joining tables is an art and the benefits and consequences of joining are not always be clear. Here, I’ll describe a simple case that works well even for a beginner learning to use tables.
Here, I’ll use the generic join to spruce up a boxplot and accentuate a pattern in the data. First, load up some data from MATLAB’s standard library.
adultdata_subset = adultdata( find(adultdata.capital_gain>0),:);
I created a subset of the data that only contains entries where individuals reported any capital gain at all. Next, graph it sideways with some data limits imposed and clipping the outliers.
I used to agonize over adding best fit lines and shaded error plots to my data. There were occasionally custom .m files passed between people online or in the lab, but these would quickly break or fail to apply to my particular use case. By learning about two simple functions and a third less simple one, you can readily craft data visualizations to meet your unique needs.
While you may go through the hassle of using polyfit and polyval, leaving a handful of variables in their wake — as I used to for years, there’s no need to do this…
If you’re lucky enough to have imaging data that you can analyze without turning to contemporary machine learning approaches or you just need a first pass, MATLAB’s regionprops is a handy tool with a lot of functionality.
Today I’ll show how you can combine some of the
First let’s make a semi-realistic looking microscopy image:
Nspots = 300;
f = randi(300,[Nspots,2]);
myimage = accumarray(f,normrnd(100,100,[Nspots,1]),[300,300]);
myimage = imfilter( myimage, fspecial('gaussian',20,3) ) + poissrnd(1,300);
The next step is to threshold the image and eliminate any stray particles:
threshold = range(range(myimage)).*graythresh(myimage);
thresholded = myimage > threshold;
thresholded = bwareaopen( thresholded, 5 );
As you acquire, store and analyze data, you will likely encounter many different variable types and data structures in MATLAB. These different data types may appear in your MATLAB workspace as the product of built-in or custom MATLAB functions, but you may also find that for some of your data, cells make sense whereas in other cases you’d turn to a table or structure. It’s great to try and think ahead about what will work best for you. But fortunately there are dozens of conversion functions, and today I’ll be documenting some of the most commonly-used ones.
In general, almost…
In MATLAB, the outputs of sort and unique go beyond what their names suggest. They are both valuable tools for data analysis.
There are situations when you may want to return the order of your data. For example, to sort another data set. Other times, however, you may want to convert your data into ranks. You can use the optional outputs from sort to help you order your input vector (or another vector).
When it comes to making a custom vector or matrix containing exactly the data you want, accumarray offers a fast and readable solution.
That’s it. That’s the post! Basically, accumarray gives you the ability to throw elements of a second array (colored squares) into the positions specified by the first array (white squares). These arrays must be columns.
Here’s how it looks in MATLAB:
accumarray( [1;1;1;2;2;2], [10,1,35,11,3,15] )
Here is the most complicated thing about using accumarray: creating a vector that specifies the positions of your data. Intuitively, when you bin data, you want to place the first three numbers…
One of the problems with some of MATLAB’s built-in statistics functions is that they break when any of the input values are NaN. In this post I’ll show you a great opportunity to build on some of MATLAB’s extremely useful NaN-friendly versions of sum, mean, and std. This skill will allow you to replace NaN-unfriendly functions like corrcoef and zscore with your own custom functions that work in a variety of situations.
Many of the tips that I outline in my ‘30 Days of MATLAB Tips’ rely on setting properties that most people don’t know about. Anyone can use the set function without any arguments to peek at all the possible properties and settings of a MATLAB object. Many of these properties and settings aren’t documented or aren’t well documented. And anyways, it’s much faster to see the options available to you than to go poring over documentation.
Here’s a quick demonstration and then a couple of cool examples of what you can do. Run the code below:
fig = figure();
If you want to make plots with displays that you can manipulate, this is the post for you. However, unless you already have experience using dynamic cursor mode, you will want to first jump over to my posts from Day 10 and Day 11.
It’s great to show the averages of your time series data to compare groups, but sometimes you also want to see the spread of the underlying data. Using a dynamic update function will help you easily accomplish this, and it’ll look great too.
We’ll make some slightly complex data, based on a sigmoid function. …
Neuroscientist and data scientist at Columbia University. On Twitter: @NeuroJoJo