Matlab to C++: Accessing a 1228x681 Matrix

  • Context: MATLAB 
  • Thread starter Thread starter schabbir
  • Start date Start date
  • Tags Tags
    C++ Matlab
Click For Summary

Discussion Overview

The discussion revolves around accessing a 1228 x 681 matrix stored in a MATLAB .mat file using C++. Participants explore various methods and considerations for handling matrix data in C++, including data structures and file formats.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant notes that C++ does not have a built-in notion of matrices and suggests that users can create their own structures using arrays or STL containers.
  • Another participant recommends saving the matrix in ASCII format and reading it into C++ using standard input operations, highlighting the need for additional parsing to convert a 1-D array into a 2-D structure.
  • A third participant provides a link to a website that may offer guidance on the topic, implying that external resources could be beneficial.
  • There is mention of the necessity to implement custom operators for matrix operations if using a user-defined matrix class.

Areas of Agreement / Disagreement

Participants express differing views on the best approach to access and manipulate the matrix data in C++. There is no consensus on a single method, and multiple strategies are proposed.

Contextual Notes

Participants do not clarify specific assumptions about the matrix data or the desired operations in C++. The discussion lacks detailed exploration of the implications of using different data structures or file formats.

Who May Find This Useful

Individuals interested in integrating MATLAB data with C++, particularly those working with matrix operations or data structures in programming.

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

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 32 ·
2
Replies
32
Views
4K
  • · Replies 4 ·
Replies
4
Views
4K
Replies
6
Views
4K
  • · Replies 5 ·
Replies
5
Views
4K