How to match Date and Data of different length?

2 views (last 30 days)
Hi, I have the following Two Date vectors (A & B) and one Data vector (C). The data in vecot C is correspond to Date in B. Now I wanna create anotehr data vector (D) which will be correspond to Date vector (A) but the data for missing date will be 0. For example:
A=[736546 736547 736548 736549 736550 736551 736552 736553 736554 736555]
B=[736546 736549 736552 736554 736555]
C=[4 5 9 7 3]
D=[ 4 0 0 5 0 0 9 0 7 3]
How to create the Vector D, with given vector A,B & C?

Accepted Answer

Stephen23
Stephen23 on 4 Feb 2020
>> D = zeros(1,numel(A));
>> [idx,idy] = ismember(A,B);
>> D(idx) = C(idy(idx))
D =
4 0 0 5 0 0 9 0 7 3

More Answers (0)

Community Treasure Hunt

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

Start Hunting!