MATLAB: A method to control on a certain variable n is present in a column (left or right) of a matrix

columnsengineeringfunctionloopMATLABMATLAB and Simulink Student Suitematrixmatrix manipulation

Hi,
Someone could help me find a method to check on a certain variable n is present in a column (left or right) of a matrix.
The matrix presents with these dimensions:
Edge = [1 2;
2 3;
3 4;
2 6;
3 7;
5 6;
6 7;
7 8];
[i,j]=size(Edge);
Thank you so much!

Best Answer

  • Possibly this?
    >> any(Edge==2)
    ans =
    1×2 logical array
    1 1 % 2 is present in both
    >> any(Edge==1)
    ans =
    1×2 logical array
    1 0 % 1 is present in first column
    >> any(Edge==9)
    ans =
    1×2 logical array
    0 0 % 9 is present in neither column
    (edit) Then how about this?
    any(Edge(:,1)==n)
    For exampe,
    >> any(Edge(:,1)==9)
    ans =
    logical
    0