Best way to lookup values in table...
Afficher commentaires plus anciens
Hi, I have a 24x12 (hourly x monthly) table of values, and a timetable that I want to look up a specific hour/month value in the Matrix. I am using the following code that uses the already calculated Hour/Month in the timetable, but its pretty slow and I'd expect there is a better/faster method.
t = 24*12 table of data values i want to look up HourlyProfile = hourly timetable with columns for Month and Hour (only used for lookup below)
for i=1:size(HourlyProfile,1)
HourlyProfile.Data(i) = t{HourlyProfile.Hr(i)+1, HourlyProfile.Mo(i)};
end
Is there a faster way to look up these values in the t table?
Thanks in advance for your help!
Réponse acceptée
Plus de réponses (1)
Peter Perkins
le 6 Avr 2018
You don't need a loop to do this. Try this:
HourlyProfile.Data = t{HourlyProfile.Hr+1, HourlyProfile.Mo}
or even
HourlyProfile.Data = t.(HourlyProfile.Mo)(HourlyProfile.Hr+1)
Catégories
En savoir plus sur Tables dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!