Mathematica Matrix creation help

Click For Summary
SUMMARY

The discussion focuses on creating a 22x10 matrix in Mathematica from multiple arrays (H1, H2, H3, etc.) using a loop. The user initially attempts to store the results using a For loop, which leads to unexpected dimensions upon importing the data. The recommended solution is to utilize the Table function instead, specifically Table[{f1[i],f2[i],..,f10[i]},{i,1,22}]>>"temp.mx", which correctly formats the output as a matrix.

PREREQUISITES
  • Familiarity with Mathematica programming language
  • Understanding of matrix dimensions and data structures
  • Knowledge of the Import function in Mathematica
  • Experience with functional programming concepts, particularly Table and For loops
NEXT STEPS
  • Explore advanced data manipulation techniques in Mathematica
  • Learn about the differences between For and Table functions in Mathematica
  • Investigate the Import function's various options for data formatting
  • Study best practices for matrix creation and manipulation in Mathematica
USEFUL FOR

Mathematica users, data analysts, and programmers looking to efficiently create and manipulate matrices from arrays of data.

NRedacted
Messages
7
Reaction score
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
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"
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
Replies
2
Views
891
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 20 ·
Replies
20
Views
5K
  • · Replies 2 ·
Replies
2
Views
12K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 4 ·
Replies
4
Views
7K