Mathematica Mathematica Matrix creation help

AI Thread Summary
The discussion revolves around the challenge of generating a 22x10 matrix from a set of data arrays (H1, H2, H3, etc.) using a loop in a programming context. The user initially attempts to create the matrix by using a For loop to compute multiple functions for each index and export the results to a file named "temp.mx." However, upon importing the data, they encounter issues with unexpected dimensions—receiving a 110-dimensional array instead of the desired 22x10 matrix.Another participant suggests that the use of the For loop may be contributing to the problem and recommends an alternative approach using the Table function. This method is proposed as a more effective way to generate the matrix directly, allowing for easier extraction of the data. The suggestion emphasizes the importance of using appropriate functions for data manipulation to avoid complications in the output format.
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
Views
2K
Replies
1
Views
4K
Replies
5
Views
4K
Replies
5
Views
3K
Replies
7
Views
3K
Replies
9
Views
3K
Replies
126
Views
19K
Back
Top