how to subset a vector with ismember(( in matlab

To subset a vector in matlab with ismember() function, you can first create a logical vector using ismember() function and then use it to subset the vector. Here is an example:

main.m
        ```
        % create a vector
        v = [1 2 3 4 5 6 7 8 9 10];

        % value to match
        match = [3 5 7];

        % create a logical vector
        idx = ismember(v, match);

        % subset vector
        subset_v = v(idx);
        ```

        In this example, we have a vector `v` and values to match in `match` vector. We use `ismember()` function to create a logical vector `idx` which is true for the elements of `v` that match with `match` vector. Using this logical vector, we subset the vector `v` to get `subset_v`.
547 chars
16 lines

gistlibby LogSnag