Create table in AppDesigner

1 次查看(过去 30 天)
I want to create a table structure that I can use within my program to store and fetch information. However, the code below results in an error of "Unrecognized function or variable 'varTypes" ". Could you direct me on what I am missing? I have a workaround but I would like to understand why the previously defined variables are not seen by the program.
properties (Access = public)
Property % Description
varNames = ["MMSI", "LAT", "LONG", "SOG", "VesselName", "VesselType", "Length", "Width"];
varTypes = ["double", "double", "double", "double", "string", "double", "double", "double"];
ship1 = table('Size',[20 8],'VariableTypes',varTypes,'VariableNames',varNames);
end

采纳的回答

Allen
Allen 2022-5-24
You cannot define variables within the properties class section. You can only define your app's properties there. If you want to only use the properties section to define you table then consider the following.
properties (Access = public)
ship1 = table('Size',[20 8], ...
'VariableTypes',["double", "double", "double", "double", "string", "double", "double", "double"], ...
'VariableNames',["MMSI", "LAT", "LONG", "SOG", "VesselName", "VesselType", "Length", "Width"]);
end
Else, you would could define varNames and varTypes as properties and then use those properties to setup your table in the startupFcn.
properties (Access = public)
varNames = ["MMSI", "LAT", "LONG", "SOG", "VesselName", "VesselType", "Length", "Width"];
varTypes = ["double", "double", "double", "double", "string", "double", "double", "double"];
ship1 {table}
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
app.Ship1 = table('Size',[20 8],'VariableTypes',app.varTypes,'VariableNames',app.varNames);
end
end
  2 个评论
Juan Romero
Juan Romero 2022-5-24
Thanks for the explanation, this solved my issue.
Allen
Allen 2022-5-25
Juan, glad to help. Be sure to accept the answer so that others looking for a similar solution may also find this helpful.

请先登录,再进行评论。

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by