# add a constant to a matrix

Hi everyone!

It’s probably a bit of a noob question: How do I add a constant vector to each line of a matrix?

I’m tracking two markers, calculate the center between the two and would now like to add an offset in a certain direction. What I have so far is:

AnyFunInterpol RFH ={
Type = Bspline;
BsplineOrder=4;
T=.RFH1.T;
Data = (.RFH2.Data+.RFH1.Data)/2;
};

Data being an AnyFloat[3][168], with 168 being the nStep of my C3D-file, which will vary from trial to trial.
Now I want to add a vector e.g. AnyVector offset={1,2,3} to each sample of the Data and for any nStep count.

Best regards
Florian

Hi Florian,
I don’t think we can create an array with a certain length specified by a constant (especially read from a C3D file), but if you know the size in advance (load it prior to the execution) - you could create 3 vectors of ones and multiply them by each component of your offset vector and further make another matrix consisting of these 3 vectors, which, in turn, will be added to the Data variable:

AnyVector ones = {1, 1, 1, … nStep times …, 1};
AnyMatrix offsetMatrix = {onesdx, onesdy, ones*dz}’;

Hope this helps.

Best regards,
Pavel

Hi Florian,

We talked here a little and realized that there is a small trick to do what you need :
AnyVector ones = iarr(1, Main.MyStudy.nStep)0 + 1;
AnyVec3 dr = {1, 2, 3};
AnyMatrix offsetMatrix = {ones
dr[0], onesdr[1], onesdr[2]}’;

the function iarr(start,end) creates a list of integers in range from ‘start’ to ‘end’.

Best regards,
Pavel

Hi Pavel,

thanks a lot! That exactly did the trick I needed.

Best regards
Florian