Go through the table with a loop and change values
이전 댓글 표시
답변 (3개)
Subhadeep Koley
2020년 2월 12일
편집: Subhadeep Koley
2020년 2월 12일
ds = record ("xlsfile", "dataset.csv");
data = dataset2table(ds);
[rows, cols] = size(data);
newData = data;
for i = 1: rows
for j = 1: cols
if table2array(data(i, j)) == -9
newData(i, j) = array2table(NaN);
end
end
end
댓글 수: 7
Megan
2020년 2월 12일
Subhadeep Koley
2020년 2월 12일
Megan
2020년 2월 12일
Subhadeep Koley
2020년 2월 12일
@Oz Can you post the dataset.csv file?
Megan
2020년 2월 12일
Megan
2020년 2월 12일
Subhadeep Koley
2020년 2월 12일
Your "dataset.csv" is encoded with UTF-16-LE, which is not fully supported by the function readtable. Therefore, I copied and pasted all the data in a new .xlsx file (attached here).
The below code might be helpful now although it is not a very efficient solution.
clc;
data = readtable('Book1.xlsx');
[rows, cols] = size(data);
newData = data;
for i = 1: rows
for j = 1: cols
temp = table2array(data(i, j));
if iscell(temp)
temp = cell2mat(temp);
end
if temp == -9
newData(i, j) = array2table(NaN);
end
end
end
Steven Lord
2020년 2월 12일
1 개 추천
The standardizeMissing function can accept arrays of various types, including table arrays and timetable arrays. If you only want to standardize the form in which missing data is stored for certain variables in your table you can tell it to only operate on specific 'DataVariables' as well.
I think you won't need to use for loop. If A is the name of the table, then you can just use:
A= readtable('dataset.csv');
A{:,:}(A{:,:}==-9) = NaN
댓글 수: 9
Megan
2020년 2월 12일
Megan
2020년 2월 12일
Try this:
A= readtable('dataset.csv');
A2 = table2array(A);
A(A==-9) = NaN;
Hope this fix the problem. I checked it using random table in my Matlab.
Megan
2020년 2월 12일
BN
2020년 2월 12일
Undefined operator '==' for input arguments of type 'table'.
did you use this line?
A2 = table2array(A);
After that we have not any table.
Megan
2020년 2월 12일
Megan
2020년 2월 12일
BN
2020년 2월 12일
Oh yes I'm sorry I had a typo, use this:
A= readtable('dataset.csv');
A2 = table2array(A);
A2(A2==-9) = NaN;
Megan
2020년 2월 12일
카테고리
도움말 센터 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!