Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.


Paul
Posts:
263
Registered:
2/23/10


streamline dereferencing of cell array into argument list
Posted:
Mar 20, 2013 6:23 PM


If I have column vectors x & y of the same length, I know that I can plot a series of points via plot(x,y). Alternatively, I can plot each vector as a series of points against their indexes via plot([x y]). But let's say that I'm interested in the first case.
Now if I wanted a quick and dirty way to plot just a handful of points [x1,y1], [x2,y2], and [x3,y3] without writing many statements, I can use:
myPts = mat2cell( [x1 y1; x2 y2; x3 y3], [3], [1 1] ) plot( myPts{:} );
This is exactly the 2vector form above, but the code keeps each pair of x & y values together instead of handling the xvector separately from the yvector. In many cases, that kind of visual binding is helpful when I'm quickly hacking through various coding possibilites in an exploratory manner because I have the coordinates in my head as numerical pairs. Granted, the need to think about the 2nd & 3rd arguments to mat2cell makes it questionable whether this is really more streamlined, but let's ignore that for now.
My question is whether there is a more direct way of getting the argument list in the 2nd statement. In the example above, I need to assign it to myPts before dereferencing the cells. It's too bad we can't do something like
plot( mat2cell( [x1 y1; x2 y2; x3 y3], [3], [1 1] ){:} )



