MATLAB: How to make a set of numbers and add numbers to it later

elementset

I want to create a set of numbers, like for example all odd numbers divisible by 3: S = {3, 9, 15} etc. I have thought of creating a vector, but in the calculation matlab doesn't see a vector as a set of numbers. Later on in my calculation I want to add even more numbers to the set S, for example I want to add the numbers {21, 27}. I have no clue how to fix this in matlab, the only thing I thought of was, as I said, creating a vector but that option doesn't seem to work for me. After creating a set of numbers I want to pick the elements out of the set and check whether they are divisible by 6 for example. But as soon as I know how to make such a set, my expectation is that picking some element out of it would be a matter of trial and error.
Is there an option in matlab to create a set of self chosen numbers, and add later even more numbers to the same set and make some more calculations with the expanded set after all? Thanks in advance.

Best Answer

Is there an option in matlab to create a set of self chosen numbers, and add later even more numbers
Yes, you just use a vector to represent your set and then concatenate more numbers to it, e.g.,
>> numset=[1 5 8 3], expanded=[numset, [4 100,7]]
numset =
1 5 8 3
expanded =
1 5 8 3 4 100 7