Click here to Skip to main content
15,898,373 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a matrix in a class and I want to use it in a method in another class can you help me
Posted

1 solution

Here's a simple example for the thin requirement you've stated:

C#
Class Matrix
{
   public Matrix (int n, int m)
   {
      // code ...
   }

   public Matrix CrossProduct(Matrix M)
   {
       // Calculate the Cross Product of this and the Matrix M
       // return the Cross Product
   }
}


// this class is using the Matrix class
Class UsingTheClassMatrixExample
{

   public static DoStuff()
   {
       Matrix M1 = new Matrix....
       Matrix M2 = new Matrix....

       Matrix CrossProduct = M1.CrossProduct(M2);
   }
}

If you need further help, like how to use the Matrix class as a dll in a different project etc let me know.

Good luck,
Edo
 
Share this answer
 
Comments
Member 8697827 15-Jul-13 8:39am    
Thank you for your reply
I have a class containing a matrix
class matrix{
public void actionPerformed(ActionEvent e)
{
dd = new double[m_Instances.numAttributes()];
for (int i = 0; i < m_Instances.numAttributes() - 1; i++)
dd[i] = Double.parseDouble(JOptionPane.showInputDialog("Enter " + m_Instances.attribute(i).name()));
}}
and I want to add the matrix to another method in another class

class matrixxx
{
public final double splitCritValue(Distribution bags, double totalNoInst) {

double numerator;
double noUnknown;
double unknownRate;
int i;

noUnknown = totalNoInst-bags.total();
unknownRate = noUnknown/totalNoInst;
numerator = oldEnt(bags) - newEnt(bags);
numerator = (1-unknownRate)*numerator;

// Splits with no gain are useless.
if (Utils.eq(numerator,0))
return 0;

return numerator/bags.total();
}}
waiting for your reply
Dalia
Joezer BH 15-Jul-13 9:15am    
Hi Dalia,
I am not sure what exactly you want to accomplish, please explain some more.

[[ Nice name - Dalia :) ]]
Member 8697827 16-Jul-13 3:13am    
Dear Dr Maimonides
The numerator= oldEnt(bags) - newEnt(bags); in splitCritValue is for each attribute so I want to add to each element in the matrix for each attribute

Dalia
Shubhashish_Mandal 15-Jul-13 10:59am    
Your Matrix class is looks like an event handler. But where is the event listener(ActionListener) .You are going to design some swing app.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900