Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab to c++ question

  1. Jul 12, 2009 #1
    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?
     
  2. jcsd
  3. Jul 12, 2009 #2
    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.
     
  4. Jul 12, 2009 #3
  5. Jul 12, 2009 #4

    MATLABdude

    User Avatar
    Science Advisor

    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
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Matlab to c++ question
  1. MATLAB questions (Replies: 0)

  2. MATLAB question (Replies: 2)

  3. MATLAB question (Replies: 1)

  4. Matlab question (Replies: 2)

  5. Matlab question (Replies: 10)

Loading...