PDA

View Full Version : More newbie questions...atan2 and referencing a row/column



jkenyon
07-02-2007, 09:19 AM
In MatLab you have the syntax some_matrix(:,[j k]) (meaning do something to columns j and k of your matrix, and in R, you can reference a column like "some_matrix[,k]". I've not yet seen an elegant way of doing this in C# or IMSL, and I wind up writing lots of clunky for/foreach loops. Is there some bit of shorthand that I'm missing?

Thanks,
Jeff

(I did have a question on why IMSL didn't have an atan2 function, but then discovered it in the standard C# math library. Duh.)

ed
07-02-2007, 12:47 PM
This is really a language implementation question. In Java, because it has arrays of arrays instead of 2D arrays, you can easily pull out in one dimension, but not the other. With C# and true 2D arrays, there's no trivial way to do this.

I have personally written some convenience functions to do this kind of thing, but they just consist of static methods that contain the required for loops. Luckily, looping in C# is quite fast whereas in Matlab looping is very slow. Another effect is that explicit looping leads to very readable code (IMO) when doing some of the tricky things possible in Matlab.

I agree that the code will be more verbose in C#, but you will not see any performance penalties. And if you're doing something often, you can cut down the amount of code you write by creating various static methods. We have thought of adding such things to the library, but most developers I've spoken to are very used to this kind of coding (granted they're not usually moving from a Matlab-like environment!).