Creating time series vectors of unequal duration

조회 수: 2 (최근 30일)
Sowmya MR
Sowmya MR 2017년 5월 15일
댓글: dpb 2017년 5월 16일
Hi,
I have two vectors: a1=[ 2 4 6 8 10...20] with an increment of 2 and a2=[2 7 12 17....50] with an increment of 5. How do i create a 3rd vector a3=[2 4 6 8....50] with an increment of 2? Bacically a3 should have a start point of a1(1) and an end point of a2(end) with an increment of 2.

채택된 답변

dpb
dpb 2017년 5월 16일
One possible interpretation...
>> inear=interp1(a2,1:length(a2),a1(end),'nearest');
>> a3=[a2(1:inear-1) a2(inear):2:a2(end)]
a3 =
2 7 12 17 22 24 26 28 30 32 34 36 38 40 42 44 46
>>
NB: You can't create your a2 above as 2:5:50 with 50 as the last element because 2+n*5=50 --> n=48/5 --> noninteger. Hence the above ending at 46.
You're second description in original posting said you wanted "a 3rd vector a3=[2 4 6 8....50]"_ which is what the first solution above gives.
As noted, the request is ambiguous at best, contradictory in its details as given.
  댓글 수: 2
Sowmya MR
Sowmya MR 2017년 5월 16일
Thanks a ton.. This is exactly what i needed
dpb
dpb 2017년 5월 16일
Huh! Guess the old saw of "even a blind pig..." does hold. :)

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

추가 답변 (1개)

dpb
dpb 2017년 5월 15일
"... a3 should have a start point of a1(1) and an end point of a2(end) with an increment of 2."
a3=[a1(1):2:a2(end)]; % done! :)
  댓글 수: 2
Sowmya MR
Sowmya MR 2017년 5월 16일
Thanks. But i want to know the closest point in a2 where a1 ends and then append remaining values to the length of a2.
dpb
dpb 2017년 5월 16일
Say wha'!!!??? I've no klew what that means nor how relates to the above problem description?
Show what you would expect the result to be from the two input vectors and explain how you deduced that result.

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

카테고리

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