How to remove rows from an array where there is a 1 in a logical array of the same dimensions
5 次查看(过去 30 天)
显示 更早的评论
cvs_data =csvread('spruce tree timber quality.csv',1,0);
expert_ratings = cvs_data(:,12)'; %inputs
inputs = cvs_data(:,1:11)';
correct_labels = zeros(3,length(expert_ratings));
bad = 0;
good=0;
excellent=0;
histogram(expert_ratings)
Skew1 = skewness(expert_ratings)
for k =1 : length(expert_ratings)%length(expert_ratings)
quality = cvs_data(k,12)';
if quality >= 1 && quality <=4
bad = bad+1;
correct_labels(1:3, k) =[1; 0 ; 0];
end
if quality >= 5 && quality <=6
good = good+1;
correct_labels(1:3, k) =[0; 1 ; 0];
end
if quality >= 7 && quality <=10
excellent = excellent+1;
correct_labels(1:3, k) =[0; 0 ; 1];
end
end
bad
good
excellent
correct_labels
%find bad data
%remove bad data or average it to make it good
%select the same amount of data for all qualities of trees
%remove noise from data
transposed = inputs';
outliers = isoutlier(transposed,"mean")
%we want to remove to roq where there is an outlier
good_inputs = transposed
row = 1:length(expert_ratings)
column = 1:11
if outliers(row,column) == 1
bad_rows(row) = row
end
bad_rows = nonzeros(bad_rows)
good_inputs(bad_rows, :) = []
good_inputs_tp = good_inputs'
good_correct_labels = correct_labels
good_correct_labels(:, bad_rows) = []
Hello. I am trying to find the outliers from the data given to us. The way I'm trying to do this is by using the "isoutlier" function which returns a logical array with 1s for every column in which there is an outlier. I then try to find every row where there is an outlier and store this in the variable bad_rows and then I try to remove it from the original data to create good data without outliers. However it seems as though every row is being stored and I don't know why.
0 个评论
回答(1 个)
Davide Masiello
2022-10-9
编辑:Davide Masiello
2022-10-9
The one below is just an example of how to use logical indexing for your problem.
data = ones(1,100);
data(randi(100,1,10)) = randi(100,1,10);
plot(data)
idx = isoutlier(data);
data = data(~idx);
plot(data)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!