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

조회 수: 7 (최근 30일)
Ozan Anli
Ozan Anli 2023년 3월 23일
댓글: Ozan Anli 2023년 3월 30일
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
Stephen23
Stephen23 2023년 3월 27일
편집: Stephen23 2023년 3월 27일
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.
Ozan Anli
Ozan Anli 2023년 3월 30일
Adjusted the code, ty for the Info!

댓글을 달려면 로그인하십시오.

답변 (1개)

Kevin Holly
Kevin Holly 2023년 3월 24일
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
Stephen23
Stephen23 2023년 3월 27일
"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 2023년 3월 28일
% 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 = " ";

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by