Sending a matrix with each iteration: Matlab "engine.h" c++ -



Sending a matrix with each iteration: Matlab "engine.h" c++ -

this question comes after solving problem got in question. have c++ code processes frames photographic camera , generates matrix each processed frame. want send matlab engine each matrix, @ end of execution have in stored matrices. conffused how this, send matrix in each iteration overwritting time, @ end have one. here code example:

matrix.cpp

#include helper.h mxarray *mat; mat = mxcreatedoublematrix(13, 13, mxreal); memcpy(mxgetpr(mat),matrix.data, 13*13*sizeof(double)); engputvariable(engine, "mat", mat);

i tried utilize counter dinamically name different matrices, didn't work matlab engine requires variables defined first. help appreciated. thanks.

if don't know number of frames priori, don't seek expand mxarray in c. not convenient. close start. problems can solved with:

engevalstring(engine, "your command here")

read more here.

the simplest approach like:

engputvariable(engine, "mat", mat); engevalstring("frames{length(frames)+1} = mat;");

don't that, illustration , slow. much improve preallocate, 1000 frames expand 1000 (or more appropriate number) when needed. improve not utilize cell arrays slow. instead utilize 3d array, such as:

frames = zeros(13,13,1000); frames(:,:,i) = mat; = + 1;

again, preallocate in blocks. idea. if need fast, build 3d arrays in c , ship them matlab when fill.

c++ iteration matlab-engine

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -