0

I have a vector containing a list of data (X and Y coords) which i want to compare to an array of 100 vectors (each with similar but not the same XY Coords) in order to find a match.

Each vector ranges in data size (between 10 and 20 cords) which causes issues when matching matrices of different sizes.

so in order to match i have used the matchfeatures which matches exact data which is no use as vectors different sizes.

so i made (using pdist to turn cords into distances)

threshigh = (vector1/100) * 110;
threslow = (vector1/100) * 90;

if (Vector2 <= threshigh)&&(vector2 >= threslow)   
    disp its a match
else
    not a match
end

this is perfect! but.. I cannot use operators on vectors as they only apply to scalar quantities.

how do i get around this?

it has also occurred to me even if this works and some values in the vector fall between this range it will not match unless they all do? how do i just take majority of results?

Filburt
  • 17,626
  • 12
  • 64
  • 115
Tom
  • 37
  • 1
  • 7
  • this is slightly different, that link is helpful but that question does not answer my second issue. – Tom Apr 21 '13 at 15:05

1 Answers1

0

The link of the duplicate question should solve your first problem. As for your second issue:

... even if this works and some values in the vector fall between this range it will not match unless they all do? how do i just take majority of results?

Once you have a logical array (with 1's at the positions corresponding to elements that fall within the specified range, and 0's elsewhere), you can manipulate it to your liking.

In its current form, the if statement branches only if all elements are true (logical '1'). If you know that the tested expression might be a vector (that is, an array), you can do the following:

  • Use the any command to check if at least one element in the array is true:

    if any(...)
        %// Do something...
    end
    
  • Use the all command to check if all elements are true:

    if all(...)
        %// Do something...
    end
    

    (using all here is superfluous, but it does enhance readability...)

  • Check for a majority of '1's by using mode:

    if mode(double(...))
        %// Do something...
    end
    

    mode returns the most frequent element in the array, so if it's '1' the if statement will branch.

Eitan T
  • 32,660
  • 14
  • 72
  • 109
  • thank you! thats really healpful! but i made this 'if idx > 0 counter = counter + 1; end if idx == 0 counter2 = counter2 + 1; end' but it wont count the 0s or 1s i can see them displaying idx but it wont count them? do you know why thi is? thanks again! – Tom Apr 21 '13 at 16:08
  • oh yer forgot to write the if statements are nested inside a for loop: 'for counting = 1:length(idx)' so for the length of idx using if statements it should systematically count them all? – Tom Apr 21 '13 at 16:19
  • @Tom No, because in each iteration you're testing for `idx > 0` which, as I said, becomes kind of nonsensical if `idx` is an array. You should be testing for `idx(counting) > 0`, given that `counting` is your loop iteration variable. But why are you doing all this? It's much simpler to use [`mode`](http://www.mathworks.com/help/matlab/ref/mode.html) to get the most frequent element in an array... – Eitan T Apr 21 '13 at 16:43
  • 1
    mode will only allow double or single numerical values but because idx is logical it will nto work in mode. how ever i have now used: idx2 = double(idx); to change it to double then use mode. i believe this is working now thank you very much for your time, you have been most helpful! – Tom Apr 21 '13 at 17:03
  • @Tom Yes, my apologies, use `double` to convert the logical values to double first. I've amended my answer. – Eitan T Apr 21 '13 at 17:06