473,396 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Looking for matrix inside a matrix


Hello,
Could someone plz tell me how to implement(!) finding the number
occurrences small matrix inside a bigger one.
(They are static - with fixed size : for example 3*3 inside 6*6)
Thank you very much!
*** Sent via Developersdex http://www.developersdex.com ***
Jan 15 '06 #1
1 1667
Hi juli jul,
here is a short method to find a small matrix inside another larger matrix
(assuming they are square):
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication12
{
class Program
{
static void Main(string[] args)
{
int[,] threeByThree = new int[,]
{{1,2,3},
{4,5,6},
{7,8,9}};

int smallMatrixDimension = 3;

int[,] sixBySix = new int[,]
{ {0,0,0,0,0,0},
{0,0,0,0,0,0},
{0,0,0,0,0,0},
{0,0,0,1,2,3},
{0,0,0,4,5,6},
{0,0,0,7,8,9}
};

int largeMatrixDimension = 6;

//ASSUMPTIONS MADE:
//1. largeMatrixDimension is always >= smallMatrixDimension
//2. Both matrices are square

//place the small matrix ontop of the large matrix
//in all possible positions
for (int i = 0; i <= largeMatrixDimension -
smallMatrixDimension; i++)
{
for (int j = 0; j <= largeMatrixDimension -
smallMatrixDimension; j++)
{
//for each position that the small matrix is imposed
//ontop of the large matrix, check to see if the
//items in both matrice match item for item
if (CheckForMatch(threeByThree, sixBySix, i, j))
{
Console.WriteLine(
String.Format("small matrix found at: {0},{1}",
i, j));
}
}
}
}

private static bool CheckForMatch(int[,] matrixToFind, int[,]
matrixToSearch, int xOffset, int yOffset)
{
//assume both matrices are square
for (int i = 0; i <= matrixToFind.GetUpperBound(0); i++)
{
for (int j = 0; j <= matrixToFind.GetUpperBound(0); j++)
{
if (matrixToFind[i, j] != matrixToSearch[i + xOffset, j
+ yOffset])
{
return false;
}
}
}

return true;
}
}
}
Hope that helps
Mark R Dawson
http://www.markdawson.org


"juli jul" wrote:

Hello,
Could someone plz tell me how to implement(!) finding the number
occurrences small matrix inside a bigger one.
(They are static - with fixed size : for example 3*3 inside 6*6)
Thank you very much!
*** Sent via Developersdex http://www.developersdex.com ***

Jan 15 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: JustSomeGuy | last post by:
I need a class that is essentially a matrix (template) class. I need to be able add rows and columns as needed. any one know of such a class?
4
by: Yudan Yi | last post by:
I have a problem to copy (assign) a matrix to another matrix. Curreny, I know copy the number using loops, while it will take some time, I wonder if there have faster method. The following code...
8
by: beginner10 | last post by:
Hello! Can anyone help me? This code doesnt work. Where is the problem? Inside the files mata and matb there is (should be) 10*10 matrix. It should count a sum to new matrix. It does not work....
5
by: Anolethron | last post by:
Wrong one: void minptr (int *matrix, int rows, int columns,int *min){ int i=0,j=0; *min=*matrix; //!!!!!!!!!!!!!!!!! for (i=0; i < rows; i++) { for (j=0; j < columns; j++) { if( *min...
6
by: lovecreatesbea... | last post by:
Hello experts, I code an function to rotate a matrix by 90 degrees clockwise. The matrix can be in any size provided its length equals to width. The one minor limitation is that this requires an...
14
by: Thomas Bauer | last post by:
Hello, I search a example like that. (1,0,0,1,4,5 ) -- moving (1,0,0,1,0,0 ) -- normal matrix (-1,0,0,1,0,0 ) -- Mirror Y-Axis (0,-1,0,1,0,0 ) -- Mirror X-Axis I caluculate all in mm.
1
by: dcatunlucky | last post by:
Ok, I have an assignment to write a program that multiplies two matrices. The matrices dimensions will be user defined as well as the numbers (floating point values) inside of them. The program must...
1
by: tiddwaylll | last post by:
I once had a matrix working like this matrix So, since its indexed with 0, I used them as matrix or matrix. Then the other day, I forgot the 0 index, and used matrix. And it worked...
1
by: almurph | last post by:
Hi everyone, Concerning the Needleman-Wunsch algorithm (cf. http://en.wikipedia.org/wiki/Needleman-Wunsch_algorithm) I have noticed a possible loop. Inside the algorithm there is an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.