473,385 Members | 1,570 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,385 software developers and data experts.

How do you remove unwanted data in a 2D matrix?

2
Hello,

basically i have a 2D matrix 'a'. It contains both data i want to use and data i want to ignore.

e.g.

'a' matrix:

1.937145 -0.500000 -1.333333 0.000000 -0.103812 -1.000000 0.000000

-0.500000 1.000000 0.000000 0.000000 0.000000 -3.000000 0.000000

-1.333333 0.000000 1.333333 0.000000 0.000000 -2.000000 0.000000

0.000000 0.000000 0.000000 0.535115 -0.285115 -3.000000 0.000000

-0.103812 0.000000 0.000000 -0.285115 0.388927 0.000000 0.000000

0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000

The data i want to extract and save into another array is surrounded by extra rows and columns full of zeros. I want to save the data (minus the zeros) into another array, lets call that 'A'.

after much head scratching i cannot get this to work. can anyone do this for me?

thank you, James
Dec 31 '07 #1
3 1887
jif20
2
i forgot to mention, in order to produce this array, malloc has been used. so it has an unknown amount of columns filled with zeros.
Dec 31 '07 #2
Andr3w
42
Hi please could you clarify a bit what you mean when you say:
"is surrounded by extra rows and columns full of zeros"

But if this is of any use to truncate the zeros from one float value (I assume from the accurancy you have on the numbers on that matrix that they are floats) you could use the following function, it's simple and bulky but does the job well

Expand|Select|Wrap|Line Numbers
  1.  
  2. float truncateZeros( float numA )
  3. {
  4.   int frTemp, intTemp;
  5.   int posCounter = 0;
  6.  
  7.   // call to modf
  8.   frTemp = modf( numA, &intTemp );
  9.  
  10.   // check if the fraction part is 0L
  11.   while( frTemp != 0L )
  12.   {
  13.      // recheck but after we multiply our number with 10
  14.      numA = numA*10;
  15.  
  16.      frTemp = modf( numA, &intTemp );
  17.  
  18.      // counter
  19.      posCounter++
  20.   }
  21.  
  22.   // return the final value without the zeros
  23.   return ((numA)/(posCounter*10)); 
  24. }
  25.  
Dec 31 '07 #3
whodgson
542 512MB
You can copy the elements of one array to another array using a for loop.
e.g. For a single dimension array:
Expand|Select|Wrap|Line Numbers
  1. for(int i=0;i<20;i++)
  2. {   if(i==0.0)continue;//jumps to top of loop without copying 0.0
  3.     b[i]=a[i];}
I think you could use the same principle for a 2 dimensional array
Feb 18 '08 #4

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

Similar topics

11
by: Tony Johansson | last post by:
Hello! I have some problem with STL function remove I have two classes called Handle which is a template class and Integer which is not a template class. The Integer class is just a wrapper...
9
by: Ben R. | last post by:
Hi guys, I've got a DB table of timecards with these fields in the table: ID (Int) UserID (Int) DateWorked (DateTime) HoursWorkedOnThatDate (Double) I'd like to display a grid, with...
3
by: Danny Yeadon | last post by:
Hi I need to remove unwanted characters from phone numbers from my phone bill to analyse the data. Some examples are 02 48222222 i need to remove the space +61266667656 ...
7
by: mohammaditraders | last post by:
Write a program which overloads a binary Minus (+) operator, The program will contain a class Matrix, This class will contain a private data member Array which store int values. The class will...
2
by: Marco Biagioni | last post by:
After i've tried to update a vb 6.0 project to vb.net, using visual studio utility,i can't read correctly data bytes from a .bmp file to insert them in a matrix to operate on. Using vb 6.0 the...
2
by: Marco Biagioni | last post by:
After i've tried to update a vb 6.0 project to vb.net, using visual studio utility,i can't read correctly data bytes from a .bmp file to insert them in a matrix to operate on. Using vb 6.0 the...
0
by: Michel Esber | last post by:
Hello, Linux RedHat AS4 running DB2 V8 FP15. I have very large tables (100 Million+ rows), and I only need to keep 6 months of data online/available. The tables have a timestamp field. I...
6
by: ashish1985s | last post by:
Hello friends.. i have made on window service which is hourly update the rss news data.. but some rss comes with some ads and logos and unwanted scripts i wanted to completly remove that all...
2
by: rijaalu | last post by:
I am designing a matrix class that performs addition, multicpication, substraction and division. When ever i complie the code it shows an error. include <iostream> using namespace std; class...
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...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.