What is the right way of reading MATLAB formatted data file in C++
8 次查看(过去 30 天)
显示 更早的评论
I am trying to read a MATLAB formatted data file (data.mat) file in C++. Below is the sample code that am using.
using namespace std;
int main() {
MATFile *pmat;
pmat = matOpen("data.mat","r");
return 0;
}
I have saved the required header files in the code directory i.e. 'mat.h', 'matrix.h' and 'tmwtypes.h'.
Below is the output i am getting.
Command:
g++ main.cpp -o out
Output:
Undefined symbols for architecture x86_64:
"_matOpen_800", referenced from:
_main in main-d0f06c.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Can someone please tell me how can i fix this or what is the right way of reading a MATLAB formatted data?
2 个评论
dpb
2020-3-15
"I have saved the required header files in the code directory i.e. 'mat.h', 'matrix.h' and 'tmwtypes.h'. "
You don't need to do that, but you've not include 'd them nor apparently set a needed compiler directive for the linker.
I know absolutely nothing about C++ but the failure is in the linker
回答(1 个)
Rashed Mohammed
2020-3-18
Hi Raghav,
I understand that you are having issues compiling the C++ program which reads MAT files. The recommended way of doing this is using mex command in MATLAB.
1. First open MATLAB and setup the mex.
mex -setup -client engine C++
2. Compile the C++ file using mex
mex -v -client engine filename.cpp
3. Add the MATLAB shared libraries folder to the runtime library path of your OS. You can see how to do that here
4. Open the command prompt/terminal in the folder where the executable is present and run the executable.
Hope this helps!
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!