Help aligning two vectors with one centred on zero.

4 views (last 30 days)
Jason on 25 Oct 2016
Commented: Chaya N on 25 Oct 2016
I have a set of x values:
x1=-31, -15.5, 0, 14.9,30.2
I know that the separation should be 15 (=pitch) so I want to plot x1 against xreal then do a fit and look at the largest deviation.
I can create:
xreal=Pitch*((1:numel(x1)));
But I can't figure out how to align them AROUND 0,e.g
xreal = -30, -15, 0 , 15, 30
then I can easily plot x1 against xreal and linearly fit.
0 CommentsShowHide -1 older comments

Sign in to comment.

Accepted Answer

LauraLee Austin on 25 Oct 2016
How about this, it should allow the location of 0 in x1 to change and the number of values in set x1 to be variable as well. if true
x1 = [-31, -15.5, 0, 14.9,30.2];
Pitch = 15;
idx = find(x1==0);
numel(x1)
xreal=(Pitch*(1-idx)):Pitch:(Pitch*(numel(x1)-idx));
1 CommentShowHide None
Jason on 25 Oct 2016
Perfect, thankyou

Sign in to comment.

More Answers (2)

Chaya N on 25 Oct 2016
Edited: Chaya N on 25 Oct 2016
xreal=Pitch*((1:numel(x1)) - ceil(numel(x1)/2))
2 CommentsShowHide 1 older comment
Chaya N on 25 Oct 2016
"...align them AROUND 0"
Exactly as asked!

Sign in to comment.

Matt J on 25 Oct 2016
xreal=xreal-mean(xreal);
3 CommentsShowHide 2 older comments
Jason on 25 Oct 2016
Yes sorry, I only thought of it after you had answered.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by