Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

MATLAB vector intersection help

  1. Jan 26, 2010 #1
    i have the following double arrays:

    165 7077
    165 7045
    165 5175
    168 7305
    168 3487
    169 6196
    169 10213
    170 7048

    165 7077
    165 7045
    168 5175
    169 7305
    169 3487
    170 6196
    170 10213
    170 7048

    how do i obtain the number and percentage of common values in column 2 of array1 and array2 by the unique values in column 1?

    for which i wrote the code:

    x = unique(data2(:,1));
    n = length(data1);
    percent = [];

    for i = 1:length(x)
    count = 0;
    for j = 1:n
    if data1(j) == x(i)
    count = count+1;
    end
    end
    percent=[percent;[count/n,x(i)]];
    end

    but this doesn't work. the counter is buggy in the if statement. i need to see if the second column in both the arrays are equal to each other based on the unique value in column 1. i need an output table something like:

    165 %overlap

    in two separate columns.
     
  2. jcsd
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted