File Exchange

image thumbnail

extractor

version 1.0.0.0 (1.63 KB) by Jean-Luc Dellis
extracts data from a matrix following a value condition

1 Download

Updated 10 Jul 2007

View License

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

Cite As

Jean-Luc Dellis (2021). extractor (https://www.mathworks.com/matlabcentral/fileexchange/15519-extractor), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (6)

Taon Khuu

Although trivial but I need it for my problem and the function did that beautifully

Jean-Luc Dellis

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

Dimitri Shvorob

I agree with James Cai.

James Cai

trivial

gum bin

good!

urs (us) schwarz

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

MATLAB Release Compatibility
Created with R14
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!