473,663 Members | 2,854 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1677
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.Collecti ons.Generic;
using System.Text;

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

int smallMatrixDime nsion = 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 largeMatrixDime nsion = 6;

//ASSUMPTIONS MADE:
//1. largeMatrixDime nsion is always >= smallMatrixDime nsion
//2. Both matrices are square

//place the small matrix ontop of the large matrix
//in all possible positions
for (int i = 0; i <= largeMatrixDime nsion -
smallMatrixDime nsion; i++)
{
for (int j = 0; j <= largeMatrixDime nsion -
smallMatrixDime nsion; 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.WriteLi ne(
String.Format(" small matrix found at: {0},{1}",
i, j));
}
}
}
}

private static bool CheckForMatch(i nt[,] matrixToFind, int[,]
matrixToSearch, int xOffset, int yOffset)
{
//assume both matrices are square
for (int i = 0; i <= matrixToFind.Ge tUpperBound(0); i++)
{
for (int j = 0; j <= matrixToFind.Ge tUpperBound(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
1436
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
4791
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 explain my situation detailed. double ** matrixa, **matrixb; int nrow = 10, mcol = 10; matrixa = initmatrix(nrow, mcol); // allocate memory a matrixb = initmatrix(nrow, mcol); // allocate memory b // copy a => b for (int i=0;i<nrow;i++)
8
1714
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. Where is the problem? #include <stdio.h> main()
5
9629
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 *(matrix+(i*columns)+j) ) { min = (matrix+(i*columns)+j);
6
7440
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 extra external macro definition MTXROT_SIZE. Your comments are welcome on this code. Thank you for your time. /
14
9098
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
1956
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 check to see if the two matrices are able to be multiplied. This is the code that I have so far: #include "stdafx.h" #include <iostream> using namespace std;
1
1435
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 perfectly fine! And worse so, the program didn't work anymore when I revert that back to matrix. Also matrix now had ridiculous values inside.
1
3105
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 important decision making mechanism. Its a "if, else if, else if" structure like:
0
8436
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8345
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8548
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8634
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7371
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6186
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5657
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4182
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1757
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.