473,324 Members | 2,313 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,324 software developers and data experts.

passing a submatrix to a function

Hi all
I have the following situation.
I do have the function
Expand|Select|Wrap|Line Numbers
  1. void SwapMatrixColumns(int *matrix, const int rows, const int cols,int source, int target){
  2.     int temp, i;           
  3.     for(i=0; i < rows; i++){  
  4.         temp=matrix[(i*cols) + source];
  5.         matrix[(i*cols) + source]=matrix[(i*cols) + target];        
  6.         matrix[(i*cols) + target]=temp;
  7.     }
  8. }
which swaps two columns of a given matrix.
Now I do call this function using
Expand|Select|Wrap|Line Numbers
  1.  SwapMatrixColumns(reinterpret_cast<int*>(Hd),  ROWS,  COLUMNS, RandomInt1, RandomInt2 ); 
and everything works fine.
Now I would like to call the same function on only part of the matrix Hd let's say on the first COLUMNS/2 columns of Hd. I tried using the following
Expand|Select|Wrap|Line Numbers
  1.  SwapMatrixColumns(reinterpret_cast<int*>(Hd),  ROWS,  COLUMNS/2, RandomInt1, RandomInt2 ); 
but of course it does now work.
I am wondering how to do that without having to write a new Class that will encapsulate all the required processing.
Thanks for any hint.
GA
Oct 15 '08 #1
3 2235
boxfish
469 Expert 256MB
I'm guessing "now work" is a typo. If you give it the wrong number of columns, it has no way of knowing where one row ends and another begins. Why do you need to do it with only half the columns? It would make sense to me (and probably work) to give it only half the rows, but if you're swapping two of the columns in that half of the matrix, why is it important not to pass any more of the matrix than that to the function? Could you explain more what you're trying to do? Thanks.
Oct 15 '08 #2
Yes it was a typo. "now work" should read "not work".
Here is what I want to do:
I start with a Matrix M[0 to 15][0 to 31] but then I want to continuously swap columns of the submatrix M[0 to 15][0 to 15] until a given condition is satisfied on these columns.
GA
I'm guessing "now work" is a typo. If you give it the wrong number of columns, it has no way of knowing where one row ends and another begins. Why do you need to do it with only half the columns? It would make sense to me (and probably work) to give it only half the rows, but if you're swapping two of the columns in that half of the matrix, why is it important not to pass any more of the matrix than that to the function? Could you explain more what you're trying to do? Thanks.
Oct 16 '08 #3
boxfish
469 Expert 256MB
but then I want to continuously swap columns of the submatrix M[0 to 15][0 to 15] until a given condition is satisfied on these columns.
Are you going to be testing for this condition inside of the SwapMatrixColumns function? Because if you aren't, I still don't see anything wrong with giving the function the real number of columns. But if you are doing this test inside of the function, you will have to pass it the real number of columns as well as the fake number, because the function can't know where one row ends and the next row begins unless it has the actual number of columns. Am I making sense? The matrix
789
456
123
is just stored in memory as
789456123
so even if you just want to use
78
45
12
you have to know the number of columns per row, or else you'll be using
78
94
56
Hope this helps.
Oct 16 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: harry | last post by:
I have an object that's passed in to a function as a parameter i.e public boolean getProjectTitle(ProjectHeader_DTO obj) {...} If I then call a method on this object inside the function i.e...
17
by: John Hunter | last post by:
I have a largish data set (1000 observations x 100 floating point variables), and some of the of the data are missing. I want to try a variety of clustering, neural network, etc, algorithms on the...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
8
by: kalinga1234 | last post by:
there is a problem regarding passing array of characters to another function(without using structures,pointer etc,).can anybody help me to solve the problem.
11
by: John Pass | last post by:
Hi, In the attached example, I do understand that the references are not changed if an array is passed by Val. What I do not understand is the result of line 99 (If one can find this by line...
12
by: Andrew Bullock | last post by:
Hi, I have two classes, A and B, B takes an A as an argument in its constructor: A a1 = new A(); B b = new B(a1);
12
by: Mike | last post by:
Consider the following code: """ struct person { char *name; int age; }; typedef struct person* StructType;
7
by: TS | last post by:
I was under the assumption that if you pass an object as a param to a method and inside that method this object is changed, the object will stay changed when returned from the method because the...
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.