Egor Kraev: Just two more items on my MATLAB wishlist
I know you have probably had enough of MATLAB by now, and
this is indeed the last post in this series. After I wrote the last one, I
realized there are two more things I have long been wishing for.
The first one is simple: MATLAB does allow you to call perl scripts straight from its command line. However, as far as I could see, it doesn’t allow to call perl functions, and thus not to pass any kind of objects besides strings between perl and MATLAB.
Now in my view, this renders that feature virtually useless. The one time I’ve used a perl script it was pumping data from a remote source – but the only halfway reasonable way to put that data into MATLAB that I could find was to open a socket and pump it over as a string, and parse that in MATLAB – how much easier would it be if I could return a perl array of doubles, or a hash of such arrays, and MATLAB would convert it!
This, then, is my next-to-last wish: allow to call perl, and
python, functions from inside MATLAB, and do on-the-fly conversion of at least
arrays, strings, and structs to/from their perl/python equivalents.
My very very last wish is a bit trickier to explain. Suppose you have a vector v of length N, and a square NxN matrix A, and you want to multiply each row of A by the corresponding entry of V. Currently, you have to construct a diagonal matrix from v, and then multiply it by A, and try to remember whether you need to do A=diag(v)*A or A=A*diag(v). Now suppose that instead of one colon operator, you had a family of named colon operators – that you could just write
A(:a, :b) = A(:a,:b).*v(:a)
This makes it rather clearer which indexes of A are matched to those of v, no?
Now suppose you wanted to sum across some of those ranges, but not all – then you could mark those that you want to sum over by an exclamation sign, say. Then, multiplying a vector by a matrix could be written as
sum(A(:a,:b!) .* v(:b!)).
MATLAB already has matrix multiplication? Sure, but what about multiplying two multi-dimensional tensors across a given dimension, such as
A(:a,:b,:d)=sum( B(:a,:c!,:d).* C(:c!,:b) )
(Yes, there are legitimate modelling uses for this kind of
thing!)
In true physicist fashion, once ! is seen in an expression using colon operators, the summing might even be automatic, without needing to write sum().
No existing code would be affected, as all the expressions I suggest are not legal in current MATLAB syntax.
Would that not be a neat extension to the already concise and powerful colon operator?
This is the very last post in this series. Coming up: a discussion of HDF5, my favourite format for structured numerical data.
Send in your comments!
Egor














252)
. Suppose this function is a black box, that is all you know about it is you
can feed 












Recent Forum Discussions