How do I append data to a MAT file from C++?

조회 수: 2 (최근 30일)
flybyya23
flybyya23 2015년 6월 25일
댓글: shuangshuang kong 2018년 4월 15일
From a C++ program, I would like to continuously append data to a MAT file while the program runs. The program doesn't have to append to an existing file, but after creating the file at the beginning the program needs to append save data to the MAT file over long periods of time. mxCreateNumericMatrix appears to require the size of the variable to be known with no options to append. The program cannot keep all the data in memory and then write it upon completion.
Thanks!
  댓글 수: 1
shuangshuang kong
shuangshuang kong 2018년 4월 15일
have you solve this problem yet? can you tell me how to do?because i have also met such problem,and i dont know how to figure it out.

댓글을 달려면 로그인하십시오.

채택된 답변

James Tursa
James Tursa 2015년 6월 30일
Why does it have to be a mat file? The simplest solution is to simply write the values in binary as you go, and then when you are done close the file. Then in MATLAB use fopen and fread to read in the data (in pieces if necessary because of memory constraints).
  댓글 수: 2
flybyya23
flybyya23 2015년 7월 1일
I was attempting to use a MAT file only because I assume MATLAB has optimized loading these files and multiple variables are named/segregated when stored/loaded. This may be my only and best choice though (use my own binary format) if MATLAB/API doesn't support what I need ... I'm surprised it wouldn't allow you to do this.
James Tursa
James Tursa 2015년 7월 1일
MATLAB compresses mat files ... maybe that is what you mean by "optimized loading".
Is it your desire to write a MATLAB variable to a mat file incrementally without specifying the size, and then at the end specify the size of the variable? And do this for several variables in the same mat file?
If the variable can't be held in memory at once, is it your plan to load only pieces of it later?

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Adam Hug
Adam Hug 2015년 6월 30일
I think your best bet will be to use MATLAB Engine. This is an API that lets you run MATLAB commands using C/Fortran programs. See the following doc link for more information and examples:
  댓글 수: 1
Sean de Wolski
Sean de Wolski 2015년 7월 1일
One could also use MATLAB Compiler based executables or libraries for this.

댓글을 달려면 로그인하십시오.


Muthu Annamalai
Muthu Annamalai 2015년 7월 1일
편집: Muthu Annamalai 2015년 7월 1일
The two alternatives are nicely laid out by Adam, and James.
  1. Adam's recommendation is to use the Mex API.
  2. James's recommendation is to use the load(), csvload() like commands from MATLAB
I think following James's approach maybe quicker, and all you need in the short run.

카테고리

Help CenterFile Exchange에서 External Language Interfaces에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by