Why do I get NaNs when I try to enter characters in my UITABLE object?

1 view (last 30 days)
Hello,
I have developed a MATLAB App Designer App. As soon as this App is started, certain contents are to be output in a UITable. As soon as I start the app, all string variables outputs are NaN. I don't understand why these variables are converted to numeric data and how I can work around this. I have already read other forum posts regarding this but could not solve my problem with them.
% Function Cores Tabelle einrichten
app.UITable.ColumnWidth = {250,100,558,50};
% Alle Function Cores finden
fprintf('Searching for Function Cores ...\n');
content = dir(app.mevtool_functioncores);
dirFlags = [content.isdir];
subFolders = content(dirFlags);
subFolderNames = {subFolders(3:end).name};
app.valid_function_cores = 0;
for k = 1 : length(subFolderNames)
function_core_path = fullfile(app.mevtool_functioncores, subFolderNames{k});
function_core_xml_path = fullfile(function_core_path, 'function_core.xml');
if ~exist(function_core_xml_path)
warning('The following directory has no "function_core.xml" file: %s', function_core_path)
warning('Discard following Function Core: %s', subFolderNames{k})
continue;
else
app.valid_function_cores = app.valid_function_cores + 1;
xml_struct = readstruct(function_core_xml_path);
app.struct_function_cores(app.valid_function_cores, 1) = string(xml_struct.name);
app.struct_function_cores(app.valid_function_cores, 2) = string(xml_struct.version);
app.struct_function_cores(app.valid_function_cores, 3) = string(xml_struct.description);
app.struct_function_cores(app.valid_function_cores, 4) = "Start";
end
fprintf('Function Core #%d = %s\n', k, subFolderNames{k});
end
app.UITable.Data = app.struct_function_cores;
  3 Comments
Stephen23
Stephen23 on 27 Mar 2023
Edited: Stephen23 on 27 Mar 2023
As an aside, regarding this indexing:
subFolderNames = {subFolders(3:end).name};
As Walter Roberson wrote in that last link: "In short: if your code assumes that '.' and '..' are the first two entries in a directory, your code has a bug (even in MS Windows). If your code assumes that directory entries are returned in any sorted order, your code has a bug (in all OS.)"
The robust approach is to use SETDIFF or ISMEMBER or similar on the file/folder names.

Sign in to comment.

Answers (1)

Kevin Holly
Kevin Holly on 24 Mar 2023
Here is a quick workaround. Before loading data into the UITable, you can run the command below to make all the columns strings by default.
app.UITable.Data = " ";
Then when you input data, all of it will be strings. You can convert the string data to numeric with str2num.
  3 Comments
Stephen23
Stephen23 on 27 Mar 2023
"unfortunately this workaround does not cause the UITable to output the stings correctly for me."
Please show the code where you first create the table.
Ozan Anli
Ozan Anli on 28 Mar 2023
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
% Aktueller Speicherort der APP herausfinden
[app.mevtool_dir,~,~] = fileparts(mfilename('fullpath'));
app.mevtool_functioncores = fullfile(app.mevtool_dir, 'Function_Core');
app.mevtool_utils = fullfile(app.mevtool_dir, 'Utils');
app.WS_Info.Text = strcat('MEVTool Workspace:', {' '}, app.mevtool_dir);
% Function Cores Tabelle einrichten
app.UITable.Data = " ";
app.UITable.ColumnWidth = {250,100,558,50};
This is the beginning of the startupFcn. The first code according to the UITable is following line:
app.UITable.Data = " ";

Sign in to comment.

Categories

Find more on Dialog Boxes in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!