Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: A more matlab like way?
Replies: 2   Last Post: Feb 28, 2013 4:33 PM

 Search Thread: Advanced Search

 Messages: [ Previous | Next ]
 Bruce Bowler Posts: 303 Registered: 12/7/04
A more matlab like way?
Posted: Feb 28, 2013 10:16 AM
 Plain Text Reply

I have 2 vectors of counts. One is a subset of the other. both lists are
sorted ascending. I'd like to expand the subset list to include any count
in the big list that's within 1 of a count in the subset. For example if

large = [1 2 3 4 5 9 11 15 16 21 22 27 28 31 33];
subset = [2 4 11 21 27];

then I'd like

outlist = [1 2 3 3 4 5 11 21 22 27 28];

One way would be to (pseudo code, untested)

outlist = [];
for ix = 1:numel(subset)
low = subset(ix)-1;
high = subset(ix)+1;
temp = find(low<=large & large<=high);
outlist = [outlist large(temp)];
end

But it doesn't seem to be "the matlab way".

Is there a better way?

Bruce

Date Subject Author
2/28/13 Bruce Bowler
2/28/13 dpb
2/28/13 Bruno Luong

© The Math Forum at NCTM 1994-2018. All Rights Reserved.