473,239 Members | 1,574 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,239 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 1661
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.