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 CenterFile Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by