converting a matlab array (MAT-file) to C++ array

I have a 2-D double-precision array in MATLAB that contains specific data. I want to open and use this array in my c++ program, in the first step I save it in a mat-file. I know that MATLAB has some c functions that provide reading mat-file in c++ (matdsgn , matOpen , ...), but I have no idea how to use these functions in a c++ program. Actually, I don't know how to use a C library in C++. Any help would be appreciated.

답변 (1개)

Jan
Jan 2017년 8월 28일

1 개 추천

It would be easier to save the data as binary file:
data = rand(8, 10);
fid = fopen('File.data', 'w');
if fid == - 1
error('Cannot open file for writing');
end
fwrite(fid, ndims(data), 'uint16');
fwrite(fid, size(data), 'uint64');
fwrite(fid, data, 'double');
fclose(fid);
The reading from C++ is equivalent: Read the number of dimensions as uint16, then the dimension itself as uint64 and then the actual data.

카테고리

도움말 센터File Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기

질문:

2017년 8월 28일

답변:

Jan
2017년 8월 28일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by