Create table in AppDesigner

3 ビュー (過去 30 日間)
Juan Manuel Romero Arguello
Juan Manuel Romero Arguello 2022 年 5 月 24 日
コメント済み: Allen 2022 年 5 月 25 日
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 Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by