How can I subtract vectors of different lengths?

조회 수: 23 (최근 30일)
balsip
balsip 2016년 7월 27일
댓글: balsip 2016년 7월 27일
Hello,
I have two vectors of different lengths:
  • LargerVec (length=7012)
  • SmallerVec (length=7004)
The best way I've come up with to solve this to be able to subtract these vectors is to use SPILLOVER to crop off the last eight values in the larger vector:
spillover=length(LargerVec)-length(SmallerVec);
LargerVec(length(LargerVec)+1-spillover:length(LargerVec))=[];
% Gradients, lower-higher inlets
delta=LargerVec-SmallerVec;
This works, but I don't want to arbitrarily lose those last eight values from LargerVec. I would prefer to extend an average of SmallerVec.
Ultimately, I want the method that will be the most true to the data.
Thank you for your help.
  댓글 수: 5
dpb
dpb 2016년 7월 27일
That would like be so in the spirit of "most true to the data" as it isn't doing any extrapolating which is more risky than interpolating, even.
balsip
balsip 2016년 7월 27일
Agreed, dpb. Thank you much.

댓글을 달려면 로그인하십시오.

채택된 답변

Thorsten
Thorsten 2016년 7월 27일
편집: Thorsten 2016년 7월 27일
You do not need much code, you can simply write
delta = LargerVec(1:numel(SmallerVec))-SmallerVec;
or if you want to delete the values in LargerVec, you can use
LargerVec = LargerVec(1:numel(Smallervec));

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by