Non-numerical data is still being loaded onto table. Need advice.
Show older comments
I don't want files with non-numerical data to be load on the UI Table but its still happening despite statment given. Need advice on where I went wrong.
% Check if the property fullPath is empty
if ~isempty(app.fullPath)
% Load the table from the file
app.dataTable = readtable(app.fullPath, 'VariableNamingRule', 'preserve');
% Ensure the data is numerical
% Apply a function across each variable in the table to check if all are numeric
if any(varfun(@(x) ~isnumeric(x), app.dataTable, 'OutputFormat', 'uniform'))
errordlg('This file contains non-numerical data.', 'Data Error', 'modal');
return;
else
% If data is numerical, display it in the UI Table
app.UITable.Data = app.dataTable;
app.UITable.ColumnName = app.dataTable.Properties.VariableNames;
end
else
errordlg('Please select a file first.', 'MISSING DATA', 'modal');
end
Accepted Answer
More Answers (0)
Categories
Find more on Logical 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!