matching vectors of different length
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi
I kindly need some guidance for a problem as the one below. I am using a very large data set and perhaps the following description is the closest to the problem at hand
dates: A=[1 1 1 2 2 2 3 3 4 4 4 5 5 6 6 6]
Unique dates: B=[1 2 3 4 5 6]
Units corresponding to unique dates: C=[12 18 15 14 11 17]
Output : unit values in C corresponding to unique dates in B such as they match the order of dates appearing in A.
output= [12 12 12 18 18 18 15 15 14 14 14 11 11 17 17 17]
Thank you for any input
0 Kommentare
Antworten (1)
Andrei Bobrov
am 12 Dez. 2011
A = [1 1 1 2 2 2 3 3 4 4 4 5 5 6 6 6];
C=[12 18 15 14 11 17];
output= C(A);
e.g. [ EDIT 08:16MDT 13.12.2011 ]
A = randi([18 23],15,1)
[B B B] = unique(A)
C = randi(125,max(B),1)
output = C(B)
3 Kommentare
Dr. Seis
am 13 Dez. 2011
If your "A" matrix does not include numbers ranging from 1 : length(C), then you will most certainly get that error. Using the example above, if A = [11 11 11 12 12 12 13 13 14 14 14 15 15 16 16 16], then you could not simply do C(A) to obtain the desired result because there is no 11th, 12th, ..., 16th element - there are only 6 elements in C. You would have to us Andrei's line involving "UNIQUE" to obtain a vector with the appropriate numbers for indexing.
Siehe auch
Kategorien
Mehr zu Time Series Objects finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!