using a MATLABEngine obj to dynamically construct a timetable with dates "yyyy-MM-dd" as keys and multiple double value columns

2 次查看(过去 30 天)
Hi Experts,
1) Looking for a best practice/way to dynamically build a timetable (through a for loop that would add multiple lines) of N columns and lines, having as keys, sorted dates "yyyy-MM-dd".
The idea is to hold a MATLABEngine object, and loop through a data structure - every iteration would add a new line.
Is there an example of how would such a thing be achieved?
2) If 1 is a no-show, is there a way to convert a .NET SortedDictionary<date, double[] columns> into a matlab timetable (as a one-go, or otherwise) operation?
3) If both 1 or 2 are no-shows, what's the closest thing either in a MATLABEngine setup, or through a Matlab Runtime setup?

回答(1 个)

Ayush
Ayush 2024-4-19
Hi Andy,
Based on the pointers you have mentioned, I think the crux of your query is to have a real-time script setup to convert a .NET SortedDictionary<date, double[] column> into a MATLAB compatible format and run it using MATLAB Engine in your .NET application. Here are some possible directions that you can try out (I’ll use the same number to respond to each query):
1. A program to build a dynamic timetable while traversing through a data structure using MATLAB Engine can be created keeping in mind when to start and stop the MATLAB Engine API and the underlying algorithm for the same. Here is a code snippet for your reference to create the MATLAB function used by MATLAB Engine in the .NET application:
% Initialize an empty timetable
tt = timetable('Size', [0, N], 'VariableTypes', repmat({'double'}, 1, N), 'VariableNames', varNames);
%yourDataStructure must be the MATLAB compatible data structure after the conversion
for i = 1:length(yourDataStructure)
% Extract the current row's data
currentData = yourDataStructure{i};
% Convert the date string to a datetime object
currentDate = datetime(currentData{1}, 'InputFormat', 'yyyy-MM-dd');
% Create a temporary timetable for the current row
tempTT = timetable(currentDate, currentData{2:end}, 'VariableNames', varNames);
% Append the temporary timetable to the main timetable
tt = [tt; tempTT];
end
% Sort the timetable by row times (dates)
tt = sortrows(tt);
For more information on the use of MATLAB Engine for .NET, refer to the documentation below: https://www.mathworks.com/help/matlab/call-matlab-from-net.html
2. In the above-mentioned code, a crucial step to be understood is the data structure that would be used by MATLAB to traverse through. As per your question you need to convert a .NET SortedDictionary<date, double[] columns> into a MATLAB timetable. You can refer to the following link for a possible resolution:
3. I believe points 1 and 2 would be able to resolve your query, Here are some additional resources for your reference:
Hope it helps!

类别

Help CenterFile Exchange 中查找有关 MATLAB Compiler SDK 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by