Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store 3D matrix in text file so that it can be imported to Matlab?

Tags:

c++

io

matlab

I have a text file as an output of a c++ program. Its actually a 3x100x200 element matrix. 3x100 2d matrices over 200 timestamps. I want to store this such that I can load it in Matlab workspace and then visualize it in a 3d plot. I am not able to figure out the structure of the text file. As in where should I put a "[..]" and where ";" and where a " " or ",".

Could someone please give an example so that I can print out in the file from the c++ code in a that manner

like image 796
sleeping_dragon Avatar asked Nov 22 '25 07:11

sleeping_dragon


1 Answers

Forget the text file. Instead, write a .mat file using the Matio library. This way you will be able to quickly add some more data fields in case you need to.

If you really want to use a text file, you can first write the matrix dimensions, then all the elements, and finally do some reshaping as suggested here.

like image 156
Reunanen Avatar answered Nov 24 '25 22:11

Reunanen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!