Borrar filtros
Borrar filtros

Create table in AppDesigner

1 visualización (últimos 30 días)
Juan Manuel Romero Arguello
Juan Manuel Romero Arguello el 24 de Mayo de 2022
Comentada: Allen el 25 de Mayo de 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

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Tables en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by