Hello everyone, I want to restrict the domain of a vector to return it to a smaller data set. For example, X between 2 and 7
Show older comments
X = [ 1 2 3 4 5 6 7 8 9 10 ];
Accepted Answer
More Answers (2)
Try this:
X = [ 1 2 3 4 5 6 7 8 9 10];
mask = X > 2 & X < 7; % Or X >=2 & X <= 7
X = X(mask)
X = [ 1 2 3 4 5 6 7 8 9 10 ];
idxToKeep = (X>=2) & (X<=7);
Xkeep = X(idxToKeep)
You can also do it all in one line, without the intermediate variable
Xkeep = X((X>=2)&(X<=7))
or not define a new variable, if you don't need one
X = X((X>=2)&(X<=7))
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!