How to fix this problem?

16 ビュー (過去 30 日間)
Julius Rinaldi Simanungkalit
Julius Rinaldi Simanungkalit 2020 年 9 月 3 日
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?

回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 9 月 3 日
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 件のコメント
Julius Rinaldi Simanungkalit
Julius Rinaldi Simanungkalit 2020 年 9 月 3 日
Can I send you my assignment and you are willing to correct it?
Julius Rinaldi Simanungkalit
Julius Rinaldi Simanungkalit 2020 年 9 月 3 日
can i ask your email

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by