cell2nancat documentation
The cell2nancat function concatenates elements of a cell into a NaN-separated vector.
Back to Climate Data Tools Contents
Contents
Syntax
xv = cell2nancat(xc) [xv,yv,...,zv] = cell2nancat(xc,yc,...,zc)
Description
xv = cell2nancat(xc) concatenates the numeric arrays of cell array xc into a single vector separated by NaNs.
[xv,yv,...,zv] = cell2nancat(xc,yc,...,zc) as above but for any number of cell arrays.
Example
CDT comes with data for all the national and US states boundaries. Here's the format it's in:
load borderdata whos % prints name & size of each variable in workspace
Name Size Bytes Class Attributes GEOM 1x4 32 double clat 302x1 36240 cell clon 302x1 36240 cell lat 302x1 4629240 cell lon 302x1 4629240 cell places 302x1 40192 cell
Thos are all cell arrays. Each of those 302 arrays contains the borders of a different state or country. To see what that looks like, here are the names and latitudes of the first three countries:
[places(1:3) lat(1:3)]
ans = 3×2 cell array {'Antigua and Barbuda'} {1×50 double} {'Algeria' } {1×1242 double} {'Azerbaijan' } {1×876 double}
If you want to plot all the borderlines, your first inclination might be to loop through each of the 302 entries and plot them individually, like this:
hold on for k = 1:302 plot(lon{k},lat{k}) end
However, looping is computationally slow and you might not want 300+ different objects plotted in your figure. So instead, you can turn each cell array into a vector and plot everything together.
Here's how cell2nancat works: Give it a cell array, and get a vector in return:
latv = cell2nancat(lat); whos lat latv
Name Size Bytes Class Attributes lat 302x1 4629240 cell latv 574729x1 4597832 double
Now that 302x1 cell array has been turned into a 574729x1 vector array containing all the borderlines from lat. To use the function on multiple cell arrays, just enter them all into cell2nancat:
[latv,lonv,clatv,clonv] = cell2nancat(lat,lon,clat,clon); plot(lonv,latv,'b') % blue borderlines hold on plot(clonv,clatv,'r.') % landmass centroids as red dots
Author Info
This function is part of the Climate Data Toolbox for Matlab. The function and supporting documentation were written by Chad A. Greene of the University of Texas at Austin.