Find the difference between rows and substract it

Hi,
So I have a Matrix (158x101), where the rows represent the number of steps, and the columns the length of the steps.
Since the steps are not starting all at the same time and have different lengths, this Matrix has Nans at the end to compensate for the shorter steps.
I want to find the step with the lowest starting value and then substract the difference from the values from that step by the other steps. In order to put them starting at the same time.
When plotting the steps I have now this:
Where the red *, represent the mean. And since I am losing a lot data to find the mean and I would like to put them, as I said before, starting at the same point.
% find the step with the lowest value
min_A1=min (Amtx1(:,1));
indice_min_A1=find(Amtx1 == min(Amtx1(:,1)));
That's what I have so far, the lowest value and the indice (or the number os the step, where that occours).
Not sure now how to do the rest.
Thanks in advance

9 Comments

Note that your code can be simplified to
[min_A1, indice_min_A1] = min(Amtx1(:, 1));
What do the number in Amtx1 actually represent. What does "the values for that step" actually mean? From your description it sounds like you have two different things, the timing of a step and the value of a step, but it's not clear how both are stored.
Amtx1 is a matrix (158x101), that represents the Values in the X-Axis of the steps during the stance phase and I have another Matrix - Amtx3(158x101), representing the Z-Axis.
so the plot that is showed is actually:
plot(Amtx1,Amtx3)
The timing would be the stance phase (each step as different length)
and the value would be the Ground Reaction Force during that time.
So wouldn't
plot(Amtx1 - Amtx1(1, :), Amtx3) %offset each column of Amtx1 to 0
do what you want?
That puts indeed all steps starting at the same point, but the rest of the data remains the same and I would like to shift the data from all the steps to that starting point.
That's why I would like to find the difference and then substract it for all the values
You keep forgetting to attach Amtx1 and Amtx3, thus delaying a good answer.
I don't get what should be subtracted from the values. Shifting a time base by x amount doesn't mean that the value should shift as well.
The plot is the sagital plane of the Ground Reaction Force from the steps in the stance phase.
The idea is to shift the steps to the lowest first value of Amtx1. so all the steps could start at that particular point and not somewhere along the X-axis.
Amtx1 would be the X-Axis from the plot and Amtx3 the Y-axis.
Both variables are attached.
Thanks for the help.
Again, I don't understand how the shift of Amtx1 (your x axis) affects Amtx3 (the y axis). Could you give a simple example of inputs and desired output. E.g:
Amtx1 = [[1; 2; 3], [0.5; 1.5; 2.5] [2; 3; 4]] %3 columns of x values
Amtx3 = [[1; 2; 3], [2; 2; 2], [3; 2; 1]] %and corresponding columsn of y values
newAmtx1 = ??
newAmtx3 = ??
It wouldn't affect Amtx3, that one would stay the same. I would shift the values only along the X-axis.
So following your example I would have:
Amtx1 = [[1; 2; 3], [0.5; 1.5; 2.5] [2; 3; 4]] %3 columns of x values
Amtx3 = [[1; 2; 3], [2; 2; 2], [3; 2; 1]] %and corresponding columsn of y values
%Since the first lowest value of Amtx1 is 0.5. I would shift all the data to
%begin there, so I would substract the difference to all Amtx1 points.
New_Amtx1=[[0.5;1.5;2.5], [0.5; 1.5; 2.5], [0.5;1.5;2.5]] % -0.5 in the 1st row, -1.5 in the 3rd row
Amtx3 = [[1; 2; 3], [2; 2; 2], [3; 2; 1]] % stays the same

Sign in to comment.

 Accepted Answer

I'm not sure how that is diferent from shiftng to 0, but to achieve what you want:
shift = Amtx1(1, :) - min(Amtx1(1, :));
plot(Amtx1 - shift, Amtx3);

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!