Reputation: 4249
I'm converting an algorithm from Matlab to C#.
At a certain point, there's this new vector in the matlab code:
F = [D * z + v; m1 + rgb];
D
is a 36x36 matrix, z
and v
are 36x1 vectors, m1
and rgb
are 3x1 vectors. This means that F
is a 39x1 vector.
Now, when converting this code to C# using MathNet, I found out that, apparently, there's no append function, and the best that I could come to is this code:
var F = Vector<float>.Build.Dense(39);
var firstElements = Vector<float>.Build.Dense(36);
var lastElements = Vector<float>.Build.Dense(3);
firstElements = D * z + v;
lastElements = m1 + rgb;
firstElements.CopySubVectorTo(F, 0, 0, firstElements.Count);
lastElements.CopySubVectorTo(F, 0, firstElements.Count, lastElements.Count);
Is there a quicker way to create the F
vector?
Upvotes: 1
Views: 2129
Reputation: 98
Not especially pretty, but this would work:
F = firstElements.ToColumnMatrix().Stack(lastElements.ToColumnMatrix()).Column(0);
It would probably be a good feature to add, a function to Stack 2 vectors.
Upvotes: 2