Matlab to C++: Accessing a 1228x681 Matrix

  • Context: MATLAB 
  • Thread starter Thread starter schabbir
  • Start date Start date
  • Tags Tags
    C++ Matlab
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
3 replies · 2K views
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