How to place NaN instead of " " / [ ] or empty field by using standardizeMissing?

조회 수: 2(최근 30일)
Hi, everyone
I have tried standardizeMissing by using Readtable at that link (I just want to replace the number of 99999.00 with NaN but not with an Empty Field) , But when i want to use it manually from Table converted from Readmatrix by using this code :
[namafile,direktori]=uigetfile({'*.txt', 'Text-files (*.txt)';'*.sec', 'Seconds-Files (*.sec)';'*.min', 'Minutes-Files (*.min)'},'Load Data Magnet LEMI Non IAGA Non RAW (Menitan / Detikan)', 'Multiselect','on');
full = fullfile(direktori,namafile);
namafiles = cellstr(sort(namafile)); %Mensortir Kombinasi Data Yang Dipilih secara acak (PENTING)
nfiles = size(full,2);
f = cellstr(full);
file = length(f);
opts = delimitedTextImportOptions('Delimiter',' ',...
'VariableNames', {'VarName1','VarName2','VarName3','VarName4','VarName5','VarName6','VarName7','VarName8','VarName9','VarName10','VarName11','VarName12','VarName13'},...
'WhiteSpace', '');
opts.MissingRule = 'fill';
Bs = readmatrix(full, opts);
Bfix = cell2table(Bs);
tabs = table(Bfix.Bs1, Bfix.Bs2, Bfix.Bs3, Bfix.Bs4, Bfix.Bs5, Bfix.Bs6, Bfix.Bs7,...
Bfix.Bs8, Bfix.Bs9, Bfix.Bs10, Bfix.Bs11, Bfix.Bs12, Bfix.Bs13);
tabss = varfun(@cell2mat,tabs);
B = standardizeMissing(tabss,{'99999.00', 'N/A'});
data = B(:,{'cell2mat_Var1','cell2mat_Var2','cell2mat_Var3','cell2mat_Var4','cell2mat_Var5','cell2mat_Var6','cell2mat_Var7','cell2mat_Var8',...
tahun = str2num(data.cell2mat_Var1);
bulan = str2num(data.cell2mat_Var2);
tanggal = str2num(data.cell2mat_Var3);
jam = str2num(data.cell2mat_Var4);
menit = str2num(data.cell2mat_Var5);
detik = str2num(data.cell2mat_Var6);
x = str2num(data.cell2mat_Var7);
y = str2num(data.cell2mat_Var8);
z = str2num(data.cell2mat_Var9);
DOF = str2num(data.cell2mat_Var13);
Dlemi = datetime(tahun,bulan,tanggal,0,0,0,'TimeZone','Asia/Jakarta', 'Format', 'yyyy-MM-dd');
D1 = datetime(tahun,bulan,tanggal,0,0,0,'TimeZone','Asia/Jakarta');
DOHSlemi = sqrt((x.^2)+(y.^2));
DOFSlemi = sqrt((x.^2)+(y.^2)+(z.^2));
The result of variable B (StandardizeMissing) is :
cell2mat_Var1 cell2mat_Var2 cell2mat_Var3 cell2mat_Var4 cell2mat_Var5 cell2mat_Var6 cell2mat_Var7 cell2mat_Var8 cell2mat_Var9 cell2mat_Var10 cell2mat_Var11 cell2mat_Var12 cell2mat_Var13
_____________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ ______________ ______________ ______________ ______________
2019 07 14 00 00 59 2027.10 -14498.37 35956.37 0.056406 -0.383280 38769.36
2019 07 14 00 01 59 35898.87 2027.14 -14498.32 35956.06 0.056408 -0.383282 38769.05
2019 07 14 00 02 59 35898.79 2027.35 -14498.38 35955.99 0.056414 -0.383284 38769.02
Look at the cell2mat_Var7 row 1, its should be placed with NaN instead of " " or an empty field like that.....
The total amount of rows from each variable at the tables is should be 1440, but because using StandardizeMissing, the cell2mat_Var7 only contain with 1439 (missing 1 field). And because of that, the code become error at DOHSlemi :
Matrix dimensions must agree.
Error in lemi2comp (line 56)
DOHSlemi = sqrt((x.^2)+(y.^2));
So, how to use standardizeMissing function correctly to create NaN data instead of " " or an empty field by using a Table input?
B = standardizeMissing(A,indicator)
B = standardizeMissing(A,indicator,'DataVariables',datavars)
Thank you Community, i hope you can understand what the purpose of my question....
Thank you so much and please help me in finding the solution (i had already attached my data).... /.\ /.\ /.\

채택된 답변

Steven Lord
Steven Lord 2021년 9월 19일
My guess is that the data that was read into that 7th variable in your table was not numeric data but included data that MATLAB interpreted as text data. In that case the appropriate missing value for that variable is empty text, not NaN.
Can you show the output of this command?
  댓글 수: 3
Tyann Hardyn
Tyann Hardyn 2021년 9월 25일
Yes, Sir, i want the data to be in a form of NaN as the output, so the data input should be a Number? Alright, Sir, so i must to create a condition that the imported data is in a number (double).

댓글을 달려면 로그인하십시오.

추가 답변(0개)


Find more on Characters and Strings 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!

Translated by