newdata=extractor(data,cn,valinf,valsup)
extracts from DATA, all the lines whose the CNth column
has values included between valinf and valsup
DATA = matrix N X M
CN = Column Number (target)
VALINF = Low limit
VALSUP = High limit
NEWDATA = Extracted Matrix
Example:
a =
1 2 3
4 5 6
1 7 8
1 4 9
4 7 2
9 6 5
extract data with third column included between 0 and 5:
>> extractor(a,3,0,5)
ans =
1 2 3
4 7 2
9 6 5
extract data with first column exactly equal to 4:
>> extractor(a,1,4,4)
ans =
4 5 6
4 7 2
Jean-Luc Dellis (2021). extractor (https://www.mathworks.com/matlabcentral/fileexchange/15519-extractor), MATLAB Central File Exchange. Retrieved .
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Create scripts with code, output, and formatted text in a single executable document.
Although trivial but I need it for my problem and the function did that beautifully
Thanks to Urs. I have followed your clever suggestions, except the multi-target that required much work...
I agree too with James and Dimitri, the code is trivial but it has helped me as maybe it could help others.
Cheers
I agree with James Cai.
trivial
good!
a simple one-liner, which works mostly as expected.
error checks should include
- correct number of input arguments
- desired column should be within the size of the matrix
furthermore
- as mlint suggests - the FIND is not necessary and should be replaced by logical indexing
- it would be nice, if the user could enter more than one column to be tested for; the result could be and-ed...
us