Create table in AppDesigner

3 Ansichten (letzte 30 Tage)
Juan Manuel Romero Arguello
Kommentiert: Allen am 25 Mai 2022
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

Akzeptierte Antwort

Allen
Allen am 24 Mai 2022
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 Kommentare
Juan Romero
Juan Romero am 24 Mai 2022
Thanks for the explanation, this solved my issue.
Allen
Allen am 25 Mai 2022
Juan, glad to help. Be sure to accept the answer so that others looking for a similar solution may also find this helpful.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by