필터 지우기
필터 지우기

How to remove incomplete elements in a vector? using loops

조회 수: 1 (최근 30일)
Sandie Nhatien Vu
Sandie Nhatien Vu 2016년 8월 6일
편집: Sandie Nhatien Vu 2016년 8월 6일
I have an experiment consisting of id numbers (x.y), where x = experiment number and y = part number.
If l have a vector, let's say:
v(id) = [1.3, 2.2, 2.3, 2.1, 1.1]
and want to remove the incomplete ones, namely: in experiment 1 because part 2 is missing
How can l do that and get the output: ans = 2.2, 2.3, 2.1 (it should remain in the same order as the original)
  댓글 수: 2
Walter Roberson
Walter Roberson 2016년 8월 6일
Why are you not removing the 2.* series as well, since part 42 of that is missing?
Sandie Nhatien Vu
Sandie Nhatien Vu 2016년 8월 6일
Because if there is are 3 id-numbers with the same experiment is complete.

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

채택된 답변

Guillaume
Guillaume 2016년 8월 6일
This should work:
v = [1.3 2.2 2.3 2.1 1.1];
requiredcount = 3;
experiments = floor(v)';
[uexp, ~, idx] = unique(experiments);
expcount = accumarray(idx, 1);
exptodiscard = uexp(expcount < requiredcount);
v(ismember(experiments, exptodiscard)) = []
Note that this entirely ignore the part number, it just counts the number of times an experiment is found and if it is less than the required count it is discarded. Therefore, it assumes that part numbers within an experiment are unique.
  댓글 수: 1
Sandie Nhatien Vu
Sandie Nhatien Vu 2016년 8월 6일
편집: Sandie Nhatien Vu 2016년 8월 6일
Thank you! Can i create a function using loops to solve this? That's is required... That's difficult?

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by