Mathematica Matrix creation help

In summary, the conversation discusses the issue of creating a 22x10 matrix from given data using For[] and how it can result in unexpected problems. Alternative methods are suggested to achieve the desired result.
  • #1
NRedacted
8
0
Hi,

I have a whole bunch of data (Arrays of the form H1, H2, H3 etc) that I want to crunch to create 10 more variables. I did:


For[i=1,i<23,i++,{f1(i),f2(i),..,f10(i)}>>>"temp.mx"]

Where fj(i)= fj(H1[],H2[],...), the functions are different functions of the numerical data I have.

Now when I try to Import "temp.mx" I get all kinds of things except a 22x10 matrix that I really badly want.

data5=Import["temp.mx","Table"]
Dimensions[data5]

This gives the result that data is 110 dimensions where each of my 10 data for each "i" is stored as 5 separate pieces of data, giving data5 a dimenion of 5*22=110

When I do


data5=Import["temp.mx"]
Dimensions[data5]


This time I get Dimension {} and all data is stored as one piece.

How can I store my calculations such that the result is a 22x10 matrix from which data can be easily extracted? This situation is driving me insane. Any help will be greatly appreciated.

Thanks
 
Physics news on Phys.org
  • #2
NRedacted said:
Hi,
I did:
For[i=1,i<23,i++,{f1(i),f2(i),..,f10(i)}>>>"temp.mx"]

I understand this compulsion to use For[] cannot be resisted.
The result is often problems like what you are seeing.

Try
Table[{f1,f2,..,f10},{i,1,22}]>>"temp.mx"
 

1. How do I create a matrix in Mathematica?

To create a matrix in Mathematica, you can use the command Table[expr, {i, imax}, {j, jmax}], where expr is the expression to be evaluated, i and j are the indices of the rows and columns, and imax and jmax are the maximum values for the indices.

2. How can I input specific values into a matrix in Mathematica?

You can input specific values into a matrix in Mathematica by using the command Array[array, {i, imax}, {j, jmax}], where array is the list of values to be inputted, i and j are the indices of the rows and columns, and imax and jmax are the maximum values for the indices.

3. Can I create a matrix with random values in Mathematica?

Yes, you can create a matrix with random values in Mathematica by using the command RandomReal[{min,max}, {i,imax}, {j,jmax}], where min and max are the minimum and maximum values for the random numbers, i and j are the indices of the rows and columns, and imax and jmax are the maximum values for the indices.

4. How do I add or multiply matrices in Mathematica?

To add or multiply matrices in Mathematica, you can use the commands Plus[matrix1, matrix2] and Times[matrix1, matrix2], respectively. Make sure that the matrices have the same dimensions for addition, and that the number of columns in the first matrix is equal to the number of rows in the second matrix for multiplication.

5. Is there a way to transpose a matrix in Mathematica?

Yes, you can transpose a matrix in Mathematica by using the command Transpose[matrix]. This will swap the rows and columns of the matrix, creating a new matrix with the columns becoming the rows and vice versa.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Advanced Physics Homework Help
Replies
1
Views
2K
  • Linear and Abstract Algebra
Replies
1
Views
3K
  • Introductory Physics Homework Help
Replies
4
Views
7K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
10K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
11K
  • Computing and Technology
Replies
6
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Introductory Physics Homework Help
Replies
2
Views
5K
Back
Top