Why do I get NaNs when I try to enter characters in my UITABLE object?
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Stephen23
il 27 Mar 2023
Modificato: Stephen23
il 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.
Risposte (1)
Kevin Holly
il 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 Commenti
Stephen23
il 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.
Vedere anche
Categorie
Scopri di più su Develop Apps Using App Designer in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!