... and here is a more or less direct translation of the Matlab code that
should now be obvious given your previous responses:
> m <- matrix(1:6, nr=2, byrow = TRUE) ## Matlab order
> m
[,1] [,2] [,3]
[1,]123
[2,]456
> sweep(m, 2, 2:4, "/")
[,1] [,2] [,3]
[1,
Why anything but sweep?
The fundamental data type in Matlab is a matrix... they don't have vectors,
they have Nx1 matrices and 1xM matrices.
Vectors don't have any concept of "row" vs. "column". Straight division is
always elementwise with recycling as needed, and matrices are really vectors in
> t(t(NN)/lambda)
[,1] [,2] [,3]
[1,] 0.5 0.667 0.75
[2,] 2.0 1.667 1.50
>
R matrices are column-based. MATLAB matrices are row-based.
> On Feb 27, 2024, at 14:54, Evan Cooch wrote:
>
> So, trying to convert a very long, somewhat technical bit of lin alg
> MATLAB code to R.
So, trying to convert a very long, somewhat technical bit of lin alg
MATLAB code to R. Most of it working, but raninto a stumbling block that
is probaably simple enough for someone to explain.
Basically, trying to 'line up' MATLAB results from an element-wise
division of a matrix by a vector wi
4 matches
Mail list logo