Problem with intersect function?
이전 댓글 표시
I am writing a matlab programm to import xls files from local and do some calculations. These xls files alwasys have four cloummns but different number of rows, each colummn from left to right is considered as a, b,c and d. And my code need to compare two adjacent rows, when they meet some conditions, put results in a matrix. I am using a nested loop to compare rows, and use intesect command to keep the order of the matrix and suppress repeated rows. But here is the problem, because intersect function will suppress repeated rows for each matrix before compare the value, so if there are repeated rows in the original data, my code will fail. Any advice? Thanks.
[vert,horz]=size(data);
for ii=1:vert-1;
for jj=ii+1:vert;
if data(ii,1)+data(jj,1)-data(ii,2)-data(jj,2)+data(ii,3)+data(jj,3)-data(ii,4)-data(jj,4)<10;
result=[data(ii,1),data(ii,2),data(ii,3),data(ii,4);data(jj,1),data(jj,2),data(jj,3),data(jj,4);result]
end
end
end
result=intersect(data,result,'stable','rows');
댓글 수: 1
I have edited you code to format the code. Please use the "{} Code" button the next time - thank you.
As far as I understand, it does not matter, that the data are coming from an Excel file and the pre-sorting in the nested loop is not a problem also. So all you are asking for is using intersect with keeping repeated rows of the inputs? But what do you expect as output then? This is not uniquely defined.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!