How to implement something similar to Vlookup with different lenght's vectors??
Mostrar comentarios más antiguos
Good afternoon everyone,
I have a very big database of financial data presented in this way:

Of course my database is much more complicated, i have around 200 equities and some thousand data each.
Like this example, also my database has different number of records for each equity.
I would like to build something like this:

I excel i could easily use the VLookup function but I'm not very confident in Matlab language and i have no idea of where i should start.
Thanks for your help.
1 comentario
Ale
el 13 de Mzo. de 2014
Respuesta aceptada
Más respuestas (2)
Chris C
el 13 de Mzo. de 2014
In order to provide you with a set of code to solve your problem I would have to know the database as a whole. However, to get you started you could write a for loop that compares each value within your array of data with a set value. For example,
desiredValue = 1000;
for i=1:size(dataSet)
if dataSet(i) == desiredValue
newValue = dataSet(i);
break;
end
i = i+1;
end
This loop would compare each item within the matrix dataSet to a desired value and would terminate when that value was located.
That should get you started. Hard to go any further without more information on the specific dataSet you're talking about.
5 comentarios
Ale
el 13 de Mzo. de 2014
Chris C
el 13 de Mzo. de 2014
Yes, that's more clear. Thanks for the clarification. Here's the algorithm I would use:
Step 1. Determine the timestamps you want. That is likely going to be decided by whichever company has the fewest number of timestamps.
Step 2. Loop through each company's data comparing the timestamp you want to find with the value at each location within the data set. Kind of confusin, so, for example:
for j = 1:length(desiredTimeStamps)
for i = 1:length(googleData(:,1))
if googleData(i,1) == desiredTimeStamp(j)
newGoogleData(i) = googleData(i,2)
end
end
end
That will run a loop for each data point within your google data set. Repeat for each company.
Then compile the results by:
newData = [desiredTimeStamps;newGoogleData;newAppleData;...];
Good luck!!!
Ale
el 13 de Mzo. de 2014
Ale
el 13 de Mzo. de 2014
Ale
el 13 de Mzo. de 2014
Ale
el 14 de Mzo. de 2014
0 votos
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!