How to implement something similar to Vlookup with different lenght's vectors??
显示 更早的评论
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.
采纳的回答
更多回答(2 个)
Chris C
2014-3-13
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 个评论
Ale
2014-3-13
Chris C
2014-3-13
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
2014-3-13
Ale
2014-3-13
Ale
2014-3-13
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!