Thread: how to search for something in the matrix which is( 2-D array)

  1. #1
    Registered User
    Join Date
    Nov 2003

    how to search for something in the matrix which is( 2-D array)

    I want to know using either C/MATLAB , how to scan the image. I want to find out if there is any number of ones (1s) exist in the matrix.
    For example:
    Say, A matrix called M is 3x3. Now if M is a binary matrix:
    M = [ 0 0 1; 0 0 0; 1 1 0];
    By observing the matrix M, we know that there are three number of ones(1ís) in the matrix, right? I think there is some kind of code we can use: using for loops, if statements , and so on. I think the concept is simple that is if you see any 1ís in the matrix; send some type of message as an output.
    HINT: we know the size of the matrix: So,
    // size of the matrix M is: // size (M)
    // int x=size of matrix;
    // for ( int i=0,  size of matrix)
    // using if statement // we are using the condition that if ( 1) is found in the matrix,// send some type of message as an output may be a cout string.
    Let me know if you understand the question, please.

  2. #2
    Advanced Novice linucksrox's Avatar
    Join Date
    Apr 2004
    i would use a for loop and iterate through the matrix, use a counter variable that is initialized to 0, and add one to it whenever you come across a 1. post some code for more help
    "What are all you parallelograms doing here?" - Peter Griffin (to Joe and his wheelchair buddies)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with matrix transpose
    By sass208 in forum C Programming
    Replies: 6
    Last Post: 12-09-2006, 02:02 AM
  2. Very handy matrix functions - part 1
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 05-20-2004, 11:38 AM
  3. Merge sort please
    By vasanth in forum C Programming
    Replies: 2
    Last Post: 11-09-2003, 12:09 PM
  4. binary search in an array
    By brianptodd in forum C++ Programming
    Replies: 4
    Last Post: 11-12-2002, 02:05 PM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 10:48 AM
Website Security Test