DataSet Row Deletion Issue

조회 수: 1 (최근 30일)
Rachel
Rachel 2014년 10월 15일
댓글: Rachel 2014년 10월 15일
Hello, I have a dataset called NO2 and vector of site IDs called SNO2. If a value in the 4th column of the data set (MonitorID) is contained in SNO2 I want to delete the entire row from the dataset. The dataset looks like this
INPUT_FID NEAR_FID DISTANCE MonitorID StationID Classification 14 18 0.137058 60711004 60712002 3
This is the code that I have written. I keep getting an error message that says the index of the matrix to remove exceeds the matrix dimensions. Thanks!
NO2=double(NO2);
for i=1:length(SNO2)
M=find(NO2(:,4)==SNO2(i))
NO2(M,:)=[]
end

채택된 답변

the cyclist
the cyclist 2014년 10월 15일
You can avoid the for loop altogether:
M = ismember(NO2(:,4),SNO2);
NO2(M,:)=[];
  댓글 수: 1
Rachel
Rachel 2014년 10월 15일
Thanks so much this works perfectly!

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

추가 답변 (2개)

Yu Jiang
Yu Jiang 2014년 10월 15일
This means M is larger than the number of rows in NO2. After you see the error message, type M in the command window to see what is the value of it, and then compare it with size(NO2).

Image Analyst
Image Analyst 2014년 10월 15일
The only thing I noticed off the top of my head was that if SNO2(i) was not found, M could be empty and you don't take that into consideration, like
if ~isempty(M)
% Found the number in column 4 of NO2.
% Delete those rows with that number.
NO2(M, :) = [];
end
I think you can do this whole loop without a loop is you use ismember().

카테고리

Help CenterFile Exchange에서 NaNs에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by