cell2nancatdocumentation

Thecell2nancatfunction 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 arrayxcinto 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:

loadborderdatawhos% 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:

holdonfork = 1:302 plot(lon{k},lat{k})end

然而,循环计算缓慢和你ight 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 howcell2nancatworks: Give it a cell array, and get a vector in return:

latv = cell2nancat(lat); whoslatlatv
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 fromlat. To use the function on multiple cell arrays, just enter them all intocell2nancat:

[latv,lonv,clatv,clonv] = cell2nancat(lat,lon,clat,clon); plot(lonv,latv,'b')% blue borderlinesholdonplot(clonv,clatv,'r.')% landmass centroids as red dots

Author Info

This function is part of theClimate Data Toolbox for Matlab. The function and supporting documentation were written by Chad A. Greene of the University of Texas at Austin.