How to fix this problem?
19 views (last 30 days)
Show older comments
Julius Rinaldi Simanungkalit
on 3 Sep 2020
Commented: Julius Rinaldi Simanungkalit
on 3 Sep 2020
function LihatData_Callback(hObject, eventdata, handles)
%% Tombol Lihat Data Testing
try
data = get(handles.uitable1,'data');
DataJ = str2double(data);%mengubah tipe data double dari cell ke bentuk float
[baris, kolom] = size(DataJ);
dataN = zeros(1,6);
DataUji = str2num(get(handles.tfDataPengujian,'String'));
th2=baris-DataUji+1;
for x = 1:DataUji
for y = 1:kolom
dataN(x,y) = DataJ(th2,y);
fprintf('\nData Testing Parameter Ke - %d Alternatif Ke - %d = %7.5f', y, th2, dataN(x,y));
end
th2=th2+1;
end
if all(cellfun(@isempty, data(:)))
msgbox('Data Masih Kosong','Warning','warn');
elseif isempty(DataUji)
msgbox('Data Pengujian Tidak Boleh Kosong','Information','help');
elseif all(~cellfun(@isempty, data(:))) && ~isempty(DataUji)
fprintf('\nJumlah Data Pengujian = %d\n',DataUji);
%dataNx = sprintfc('%7.5f', dataN);
set(handles.uitable2,'data',dataN);
set(handles.NaiveBayes, 'enable','on');
end
catch exception
msgbox(exception.identifier,'Error','error');
end
why i get NaN? and how to fix that?

0 Comments
Answers (1)
Walter Roberson
on 3 Sep 2020
Suppose that your input uitable is a cell array, and that the first column is character vectors, and the other columns are already numeric.
You str2double the entire cell array.
The first column has text that is not in the form of a number, so str2double converts it to nan.
If, hypothetically, the other entries are already numeric rather than character, then str2double would convert them to nan.
That is,str2double(123) does not look at the input and say "oh, it is already numeric, return it unchange!" : str2double would look at it and say that it is not a character vector or string() representing a valid number, and would return nan.
2 Comments
See Also
Categories
Find more on Data Type Conversion 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!