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

조회 수: 19 (최근 30일)
JoKi
JoKi 2020년 7월 19일
댓글: JoKi 2020년 8월 26일
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!

채택된 답변

Arnav Dubey
Arnav Dubey 2020년 8월 21일
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by