-
-
May 8, 2019 at 8:22 am
MollyC
SubscriberGood morning,
I have a matrix as a ".mat" file that I want to import to Ansys APDL or import just the individual values from the matrix at a time.
Â
Thank you for your help!
-
May 8, 2019 at 12:52 pm
jpasquerell
Ansys EmployeeThe *DMAT and *SMAT commands have an option to import a .MAT file. They are designed to work with a .MAT file created by the ANSYS *EXPORT command. If the .MAT file is an ASCII text file you could use *VREAD or *TREAD depending on the format used to create it. If tab or comma delimited then *TREAD is likely needed. Otherwise you need to give info on what program wrote the file and whether it is binary or text. If binary then use of user programmable features may be required.
-
May 8, 2019 at 8:42 pm
peteroznewman
SubscriberMolly, I am guessing that matlab wrote the .mat file, right?
In that case, open matlab and use a short script to write the matrix to a tab delimited text file.
You will have a much easier time importing a text file to ANSYS than the matlab binary .mat file format.
-
May 9, 2019 at 7:23 am
MollyC
SubscriberHi Peter,Â
yes matlab wrote the .mat file. When I use a text file for the matrix can I tell ANSYS that for example I just want the value from the 6 row and the 4 column?
So is there a command for a specific value (or on a specific spot) in a text file?
Â
Thank you for the Answer
-
May 9, 2019 at 7:35 am
MollyC
SubscriberHi jpasquerell,
how can I use the *EXPORT command when I didn't import the matrix before? It's a matrix with Double precision real values.
Â
Thank you for the Answer
-
May 9, 2019 at 10:49 am
peteroznewman
SubscriberHi Molly,
When I need one number from matlab, I use the Windows clipboard to copy from matlab and paste into ANSYS. If you double click on a variable name in matlab, it opens the variable in the Variables window and you can click on the one cell and copy that. Use the matlab View tab to set the Number Display Format to Long Fixed Decimal or Long Scientific Notation to get all the double precision digits.
If you must write the number to a file in a matlab script, then just modify the previous script and write out A(3,4) for example.
Jpasquerell means that ANSYS has a lot of matrices it uses, and you can export them out to an ANSYS .mat file, which is different to a matlab .mat file, but your original post did not mention matlab so he assumed you were referring to ANSYS .mat files. I guessed you were talking about matlab.
-
May 9, 2019 at 12:02 pm
MollyC
SubscriberHi Peter,
ok that sound simple but I have a matrix that is pretty big (1000 x 1000) and I wanted to write a loop. And in this loop I wanted to save the value from the x row and the y column as a specific thickness.Â
Thank you for the Answer
Â
-
May 9, 2019 at 1:57 pm
peteroznewman
SubscriberHi Molly,
If x = 357 and y = 468 and the matrix is variable M you can get out the value like this:Â M(357,468)Â and you can assign that to a variable t if you like.
t = M(357,468);
or if x and y were variables,
t = M(x,y);
-
May 13, 2019 at 5:49 am
MollyC
SubscriberHi Peter,
Â
Ok but don't I need to import the matrix first to assign t as M(x,y)? And I still can't work out how to import the matrix as .mat file from MatLab.
Â
Thank you for your answer!Â
-
May 13, 2019 at 10:39 am
peteroznewman
SubscriberHi Molly,
The code above is executed in matlab where the matrix M exists and all you want is a single value at a known row and column. Once you have that value, you can write it to a file or copy it to the clipboard to get it into ansys. You don't need the whole matrix in ansys, unless you need to extract different values in some program loop in ansys. Is that what you have in mind?
-
May 13, 2019 at 2:20 pm
sk_cheah
SubscriberHi Molly,
What jpasquerell recommended is described well by SimuTech using *TREAD and *VREAD. An alternative strategy is to write the file to Matrix Market Format. First download mmwrite.m script from NIST.gov website. You could then export the matrix from Matlab using these Matlab commands :Â
m = transpose(1:10) * (1:10); % example matrix
mmwrite('toansys.mtx', m, 'example matrix'); % writes out matrix to file
In Ansys, the APDL script to import the file :Â
*dmat, importmatrix, d, import, mmf, toansys.mtx ! imports double precision MTX file
*dim, fromMatlab, array, 10, 10 ! pre-define matrix size
*export, importmatrix, apdl, fromMatlab, 1, 10 ! writes it out to apdl array named fromMatlab, 1st column to 10th column
Now you may access the values from the imported matrix in Ansys. An example:Â
q = fromMatlab(3, 4)
*stat, q
Kind regards,
Jason -
May 14, 2019 at 7:40 am
MollyC
SubscriberHi Peter,
yes I want to write a loop so I need the hole matrix in ANSYS.Â
Â
and
Â
Hi Jason,
Ok I'll try that out, but isn't there a simpler way to import that matrix?
Â
Thank you for your answer!
-
- The topic ‘Import .mat file’ is closed to new replies.
-
5874
-
1906
-
1420
-
1306
-
1021
© 2026 Copyright ANSYS, Inc. All rights reserved.