MATLAB Matlab to C++: Accessing a 1228x681 Matrix

  • Thread starter Thread starter schabbir
  • Start date Start date
  • Tags Tags
    C++ Matlab
AI Thread Summary
To access a 1228 x 681 matrix from a MAT file in C++, users need to understand that C++ does not have built-in support for matrices. Instead, they can utilize arrays or STL containers like std::vector to create custom matrix structures. For reading the MAT file, converting it to ASCII format is recommended, allowing for easier input using cin operations. Users may also need to implement their own matrix operations, such as multiplication and addition, since C++ requires custom operator overloading for these functionalities. Resources such as the Numerical Recipes website and MATLAB's save documentation provide further guidance on handling MAT files and matrix operations in C++.
schabbir
Messages
2
Reaction score
0
Hi,

I have a mat file, which is a 1228 x 681 matrix and I want to access this file in c++. Can anyone help me how to do this?
 
Physics news on Phys.org
C++ has no notion of matrices. Unlike other languages C++ starts you out with practically nothing, but it does give you the unprecedented ability to create whatever structures you want with practically any syntax you want. Thus you can easily get matrices that behave any way you like, but you will need to build this upon the concept of arrays -- either explicitly, or implicitly by using std::vector, or someone else's matrix library.
 
You can save it in ASCII format instead, and then read it in using a cin << operation. Again, as junglebeast notes, C++ has no notion of matrices, so you can either be content with reading stuff into a long 1-D array, parsing it into a 2-D array using some loops, or possibly using an STL container class (I vaguely recall doing matrix transforms with overloaded functions years ago in my C++ class in undergrad--unfortunately, you needed to write your own operators for matrix multiplication, transposition, addition, etc.):
http://en.wikipedia.org/wiki/Standard_Template_Library

MATLAB Save documentation (look about half-way down the page, under the heading MAT-File Format Options):
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/save.html
 

Similar threads

Back
Top