Create custom Table Classes

70 次查看(过去 30 天)
Cody Brown
Cody Brown 2024-9-19,17:18
I don't believe this is a feature in MATLAB at the moment, and in that case I'm posting this more as a sugestion for future MATLAB releases. I feel as though many user would find this to be very useful.
1) I like working with matlab tables and timetables because when debugging you can see alot of data all from one location in the variables window, without having to switch between different tabs, expessily when trying to debug dozens of variables with shared indicies at once.
2) I also really like using matlab's "period & tab" codeassist that comes from using custom classes, and speficing in the arguments block for other functions and class methods the class that is being passed in, and being able to use the code assist to see all the properties/variables in that custom class.
However these 2 things can't be combine with current MATLAB functionality. You can only work around this by creating an instance of the table you want in the workspace, and leverage that being present while you are writting code to have code assist, but working through referencing something arbitrary, which could have spelling differences.
I noticed that you can't have subclasses to the table or timetable class, which may be a future means of accomplishing this in the backend of matlab (ofcorse I have no idea LOL). Ideally what I would like to have in Matlab is the ability to defign a custom table class. In this example there would be an added benifit of being able to defign the exact datatype allowed in each variable (column) of a table
classdef CustomTable < matlab.("tableTemplate")
properties (VariableNames)
%replaces "VariableNames" inside of the "TableProperties" class, held in default table class
%every unique property listed here would become a column in the custom table
%
%with this being table, each variable needs to have shared indicies
%with all other variables in the table
Time (:,1) datetime
column2 (:,1) double
column3 (:,1) double
end
methods
function obj = CustomTable()
if nargin == 0
obj.Time = [];
obj.column2 = [];
obj.column3 = [];
end
end %end of constructor
function sortData(obj)
%additional methods that organize and filter data, specific to
%this custom classes needs
end
end %end of methods
end
This would be simply so that the following 2 commands would return what is effectivly equivelent results:
%1
T = CustomTable();
%2
T = table([],[],[],'VariableNames',{'Time','column2','column3'});
This would allow you to have code assist helping you when writting code in other outside functions, provided simply your custom class .m file was on your matlab path, even if your Workspace was empty, which seems really helpful with both writting and debugging code that uses tables.

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by