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

how to know the size of a matrix?

21
I am just wondering how to measure the size of a matrix in C language?
May 24 '10 #1
5 14071
Banfa
9,065 Expert Mod 8TB
You don't measure it, you store it for later reference when you create the matrix.
May 24 '10 #2
sheff
21
hi Banfa, thnx for ur help, okay that is fine , but how this can be done? I am now assuming that I have a matrix A= [ 1 2 ; 3 4 ], how can I know the number of rows and colums of this matrix? in my program the dimenation of the matrix might not be known and need to find a way to know that, any ideas or suggestions plse?
May 25 '10 #3
Banfa
9,065 Expert Mod 8TB
The program does not deal with an undimensioned matrix, at some point the dimensions are known and at that point they should be stored in suitable variables for later use.

If this is a C program then rather than a pointer int ** or float ** to hold your matrix you might want to consider a structure like

Expand|Select|Wrap|Line Numbers
  1. struct matrix {
  2.     int xdim;
  3.     int ydim;
  4.     float **data;
  5. };
  6.  
So the matrix dimensions are carried with the matrix data at all times.
May 25 '10 #4
sheff
21
Hi Banfa, thank you for your reply, the idea is still mysterious, can you please apply the structure you wrote above on the matrix A= [ 1 2 ; 3 4 ] so I can get the idea. thank you again
May 26 '10 #5
Banfa
9,065 Expert Mod 8TB
Well assuming that you correctly filled in the members with the matrix size and allocated data for the pointer then a print function would look something like this

Expand|Select|Wrap|Line Numbers
  1. void printMatrix(const struct matrix* m)
  2. {
  3.     unsigned x;
  4.     unsigned y;
  5.  
  6.     printf("Printing %d by %d matrix\n", m->xdim, m->ydim);
  7.     for(y=0; y<m->ydim; y++)
  8.     {
  9.         for(x=0; x<m->xdim; x++)
  10.         {
  11.             if (x == 0)
  12.             {
  13.                     printf("| %2.2f", m->data[y][x]);
  14.             }
  15.             else
  16.             {
  17.                     printf(", %2.2f", m->data[y][x]);
  18.             }
  19.         }
  20.  
  21.         puts(" |");
  22.     }
  23. }
  24.  
May 26 '10 #6

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

Similar topics

6
by: Dima | last post by:
How can I know size of avaible memory in heap? For example : .... .... // size = N cout << "Size of Heap = " << SizeOfHeap() << endl; int* i = new int; // size = N - sizeof(int) cout << "Size...
27
by: Marcus Kwok | last post by:
I am getting warnings when comparing a (regular) int to the value returned from std::vector.size() in code similar to the following: int i = //stuff if (i >= vec.size()) The compiler gives...
2
by: Saeed Sedighian | last post by:
Hello All. I open a window using showModalDialog function. (window.showModalDialog('webform2.htm',null,'resizable:yes')) In modal window after page loaded i want to change size of window using...
16
by: kujahleague | last post by:
Been bothering me so long, we can find the size of string array (array of char) but what is the way to find the size for integer array? I've tried using while loop until it find '\0' null character,...
8
by: MVM | last post by:
I am new to VS 2003. I did programming in vb6 and vc6, but not through studio. I am having lot of confusion on how to start, where to start? I like to write a program in vc++ under vs 2003. i...
1
by: MrNobody | last post by:
I've got a problem where I need to create an image so I can draw to some "offline" graphics object and in order to create that image I need to specify size but I will not know size until I'm done...
15
by: subramanian100in | last post by:
Is it possible to measure the size of an array without using the sizeof operator ?
18
by: Hypnotik | last post by:
Hello everyone. I'm writing a program which uses a class called matrix. I have written all of the different functions, constructor, etc. When I run the program I receive "Constructor", which I...
4
by: .rhavin grobert | last post by:
guess you have a bouquet of paddingless structs (and your compiler already cares for that) that all have one in common: their first memeber has to be their size. As fas as i know (am i right?) a...
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...
1
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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)...
0
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...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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.