MATLAB Answers

Table in AppDesigner shows NaN, how do i solve it?

23 views (last 30 days)
JoKi
JoKi on 19 Jul 2020
Commented: JoKi on 26 Aug 2020
Hello guys,
im trying to show some data which i processed before in a table with AppDesigner. I dont get any errors by running the code but the table only shows me "NaN" instead of the Data i want.
This is my code:
% Button pushed function: EinlesenButton
function EinlesenButtonPushed(app, event)
%Diese Funktion dient dem direkten Lesen der auf dem übergeben Pfad
%hinterlegten CSV-Datei. Diese Datei muss exakt der Formatierung der
%Dateien entsprechen die das Program "Power" des Diagnostikgerätes
%liefert.
%Einlesen der Datei über den Umweg mit strings
% Öffnen eines Fensters zur Auswahl der zu öffnenden .csv Dateien.
[filename,pathname] = uigetfile('*.csv;','MultiSelect',"on");
for i = 1:length(filename)
filepath=fullfile(pathname, filename);
fid = fopen (filepath{i});
A = textscan(fid, '%s%s%s%s%s%s%s%s%s%s%s%s%s','Delimiter',';');
%Umwandeln von Cell --> String
B=string([A{:}]);
%',' durch '.' ersetzen
B=replace(B,',', '.'); % ',' durch '.' ersetzen
% Aufteilen in Header und Messdaten
Daten(i).Header=B(1:30,:);
Daten(i).Messdaten=str2double(B(31:end,7));
end
for i = 1:length(filename)
%Uhrzeit
x= char(Daten(i).Header(12,1));
x1 = extractBetween(x,13,20 );
%Datum
y = char(Daten(i).Header(11,1));
y1 = extractBetween(y,11,20);
%Bein Seite
z = char(Daten(i).Header(21,1));
if strlength(z) == 22
z1 = extractBetween(z,10,14);
else
z1 = extractBetween(z,10,15);
end
app.UITable.Data(i,2) = string(x1);
app.UITable.Data(i,3) = string(y1);
app.UITable.Data(i,4) = string(z1);
end
end
my .csv Data looks like this:
The processed Data looks like this (if this helps):
Thanks for any help!

  0 Comments

Sign in to comment.

Accepted Answer

Arnav Dubey
Arnav Dubey on 21 Aug 2020
The actual data is based on what the underlying data type of the UITable.Data property is. For example, if you create the table with data that is numeric, then the Data would be numeric. So when you try to add a string, it tries to put the string into the numeric Data -> NaN, then tries to print the numeric NaN as a 'char' which is NaN. The "NewData" is set to NaN because it is the underlying value that MATLAB wrote to the Data property array:
If you want to make sure that the table displays properly, the underlying Data types for the columns should match what you want to display.
Another workaround to this issue would be to add the following line of code in "UITableCellEdit" callback:
app.UITable.Data(event.Indices(1), event.Indices(2)) = {event.EditData}
This would convert the data to cell array and display it in the table as string.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!